The maths problem of bzoj3209 flower God

Source: Internet
Author: User

3209: The number proposition of the flower God Time limit: ten Sec Memory Limit: MB
Submit: 1612 Solved: 746
[Submit] [Status] [Discuss] Description

As we all know, the flower God over the years by virtue of the boundless power of the big OJ, OI, CF, TC ... Of course it also includes CH.
The flower God comes to lecture again this day. After class, there is a very difficult god problem. I waited for Konjac Konjac to suffer again.
The topic of the flower God is this
Set sum (i) to indicate the number of 1 in the binary representation of I. Give a positive integer N, the flower God wants to ask you
Pie (sum (i)), which is the product of sum (1)-sum (N).


A positive integer N.


A number, the value of the answer modulus 10000007.

Sample InputSample Input One


Sample OutputSample Output One


For example one, 1*1*2=2;

Data scope and conventions

For 100% of data, n≤10^15


Original Memphis

Digital DP + Number theory

F[X] Indicates the number of sum[i]=x I, then the final answer equals (1^f[1]) * (2^f[2]) * (3^f[3]) * ...

Because the base range is very small, and the 10000007=941*10627, so the basis and 100,000,071 fixed coprime, according to Euler theorem, as long as the exponent of Phi (10000007) =9988440 to take the model.

The question now is how to ask for f[x].

Digital DP from high to low, see procedure in detail.

Why all kinds of DP can't think of it ... (╯‵-′) ╯︵┻━┻

#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath > #include <algorithm> #define F (I,j,n) for (int. i=j;i<=n;i++) #define D (i,j,n) for (int i=j;i>=n;i--) # Define ll long long#define MoD 10000007#define phi 9988440using namespace Std;ll n,ans=1,c[60][60],f[60];inline ll read () { ll X=0,f=1;char Ch=getchar (); while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch>= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} inline void DP (LL x) {int tmp=0,cnt=0;ll now=0;while ((1ll<<tmp) <x) tmp++;D(i,tmp,0) if (now+ (1ll<<i) < =x) {F (J,0,i) (F[j+cnt]+=c[i][j])%=phi;cnt++;now+= (1ll<<i);}} inline ll Getpow (ll X,ll y) {ll ret=1;for (; y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;} int main () {scanf ("%lld", &n); F (i,0,50) {c[i][0]=1; F (j,1,i) c[i][j]= (c[i-1][j-1]+c[i-1][j])%phi; DP (N+1); F (i,1,50) Ans=ans*getpow (I,f[i])%mod;printf ("%lld\n", ans);

The maths problem of bzoj3209 flower God

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.