Möbius inversion of Bzoj 3930 CQOI2015 selection

Source: Internet
Author: User

Topic See HTTP://PAN.BAIDU.COM/S/1O6ZAJC2


Also do not know h-l<=10^5 this condition is why ....

#include <map> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm&
Gt
#define M 10001000 #define INF 0x3f3f3f3f #define MOD 1000000007 using namespace std;
int Mu[m],prime[1001001],tot;
BOOL Not_prime[m];
Map<int,long long> mu_sum;
Long Long n,d,l,r;
	void Linear_shaker () {int i,j;
	Mu[1]=1;
			for (i=2;i<=10000000;i++) {if (!not_prime[i]) {mu[i]=-1;
		Prime[++tot]=i;
			} for (j=1;prime[j]*i<=10000000;j++) {not_prime[prime[j]*i]=true;
				if (i%prime[j]==0) {mu[prime[j]*i]=0;
			Break
		} Mu[prime[j]*i]=-mu[i];
}} for (i=1;i<=10000000;i++) mu[i]+=mu[i-1];
	A long long mu_sum (int x) {if (x<=10000000) return mu[x];
	if (Mu_sum.find (x)!=mu_sum.end ()) return mu_sum[x];
	Long Long i,last,re=1;
		for (i=1;i<=x;i=last+1) {last=x/(x/i);
	if (x/i-1) re-= (Mu_sum (last)-mu_sum (i-1)) * (x/i-1);
} return mu_sum[x]=re;
	A long long quick_power (long long x,int y) {long long re=1; WhileY) {if (y&1) (re*=x)%=mod; (x*=x)%=mod;
	y>>=1;
} return re;
	} Long Long Solve () {long i,last,re=0; for (i=1;i<=r;i=last+1) {last=min (r/(r/i), l/i? (
		l/(l/i)): INF);
		re+= (Mu_sum (last)-mu_sum (i-1)) *quick_power (r/i-l/i,n);
	Re%=mod;
} return (Re%mod+mod)%mod;
	} int main () {cin>>n>>d>>l>>r;
	L= (L-1)/d;r=r/d;
	Linear_shaker ();
Cout<<solve () <<endl;
 }


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: info-contact@alibabacloud.com 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.