BZOJ-3209 (number theory)

topic

3209: Flower God's Number Theory
Time Limit: 10 Sec Memory Limit: 128 MB

Problem Dexcription

Let sum(i) denote the number of ones in the binary representation of i. Given a positive integer N, Flora going to ask you
to send (Sum (i)), which is the product of the sum (1) -sum (N) is.

Input

A positive integer N.
N≤10^15

Output

A number, the answer modulo 10000007 value.

Samples

Input Output
571 2560979
3 2
4 2
8 24
9 48
1000000000000000 1030503

analysis


  • You can treat n as binary and discuss it in sections.
  • Give an example to simulate it again to realize:

n=100100 (in binary system)
000001~011111 contribution is 1C152C253C354C455C15 <script type="math/tex" id="MathJax-Element-1">1^{C_5^1}2^{C_5^2}*3^{C_5^3}*4^{C_5^4}* 5^{C_5^1}</script>
100000 contribution is 1
100001~100011 contribution is 1C122C22 <script type="math/tex" id="MathJax-Element-2">1^{C_2^1}*2^{C_2^2}</script>
100 100 Contribution is 2
*There is a bit of digital dp the idea for ([1~2^n)this interval where the contribution of all the number of answers we can use the above method of seeking out the number of combinations (a classification of 1, 1 two, three ... 1), then you can put the original into a number of such n Continuous "full power of two" interval (temporary coinage), pay attention to the base to add the number of 1 that has been fixed before (this is reflected in my program as cnt).
* You can look at the program again to understand it.

program

#include <cstdio>
#define Ha 10000007
long long i,j,n,p,q,cnt,ret,ans=1ll,C[60][60];

long long ksm(long long x,long long y){
    for (ret=1; y; y>>=1,x=(x*x)%Ha)
        if (y&1) ret=(ret*x)%Ha;
    return ret;
}

int main(){
    for (C[0][0]=1,i=1; i<=55; i++)
        for (j=0; j<=55; j++)
            C[i][j]=C[i-1][j-1]+C[i-1][j];

    scanf("%lld",&n);
    for (cnt=0,p=53,q=1ll<<p; q; q>>=1,p--) if (n&q){
        for (i=1; i<=p; i++)
            ans=(ans*ksm(cnt+i,C[p][i]))%Ha;
        ans=(ans*(++cnt))%Ha;
    }

    printf("%lld",ans);
}

Guess you like

Origin blog.csdn.net/jackypigpig/article/details/78365734