GDOI2016模拟3.16 幂
Description
Sol
暴力了解一下,对每个底数容斥,发现容斥结果只跟 x=floor(log(A)/log(i))有关。
那我们单独把系数拿出来容斥。
看起来是2^29的,但是实际上远远不到。
#include<bits/stdc++.h> using namespace std; #define LL long long #define pii pair<LL,LL> map<pii,LL> mp; map<LL,bool> usd; LL m,n,ans; LL anw[38]; LL gcd(LL x,LL y){ while (y) swap(x,y),y%=x; return x; } LL dfs(LL i,LL j){ LL anw; if (i==0||j>30*m) return 0; if (mp.count(pii(i,j))) return mp[pii(i,j)]; anw=dfs(i-1,j)+(m)*gcd(i,j)/j- dfs(i-1,j*i/gcd(i,j)); return mp[pii(i,j)]=anw; } void pre(){ dfs(29,1); for (int i=1;i<=29;i++) anw[i]=i*m-mp[pii(i,1)]; } LL t,p; signed main () { // freopen("2.in","r",stdin); scanf("%lld%lld",&n,&m); pre(); ans=n*m; for (int i=2;i*i<=n;i++) if (!usd[i]){ t=i; p=1; while (t*i<=n) t*=i,p++,usd[t]=1; ans-=anw[p]; // if (p>28) printf("%d\n",p); } printf("%lld\n",ans-m+1); }