Counting Divisors HDU - 6069
生活随笔
收集整理的這篇文章主要介紹了
Counting Divisors HDU - 6069
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
設n=p_1^{c_1}p_2^{c_2}...p_m^{c_m}n=p?1?c?1????p?2?c?2????...p?m?c?m????,則d(n^k)=(kc_1+1)(kc_2+1)...(kc_m+1)d(n?k??)=(kc?1??+1)(kc?2??+1)...(kc?m??+1)。
枚舉不超過\sqrt{r}√?r???的所有質數pp,再枚舉區間[l,r][l,r]中所有pp的倍數,將其分解質因數,最后剩下的部分就是超過\sqrt{r}√?r???的質數,只可能是00個或11個。
時間復雜度O(\sqrt{r}+(r-l+1)\log\log(r-l+1))O(√?r???+(r?l+1)loglog(r?l+1))。
這道題的出題者給我膜一會,666666
#include <bits/stdc++.h> using namespace std;typedef long long ll; const int N=1000010,P=998244353; int Case,i,j,k,p[N/10],tot,g[N],ans;ll n,l,r,f[N]; bool v[N];void work(ll p) {for(ll i=l/p*p;i<=r;i+=p)if(i>=l){int o=0;while(f[i-l]%p==0)f[i-l]/=p,o++;g[i-l]=1LL*g[i-l]*(o*k+1)%P;} }int main() {//freopen("input.txt","r",stdin);//freopen("output.txt","w",stdout);for(i=2;i<N;i++){if(!v[i]) p[tot++]=i;for(j=0;j<tot && i*p[j]<N;j++){v[i*p[j]]=1;if(i%p[j]==0) break;}}scanf("%d",&Case);while(Case--){scanf("%lld%lld%d",&l,&r,&k); n=r-l;for(i=0;i<=n;i++) f[i]=i+l,g[i]=1;for(i=0;i<tot;i++){if(1LL*p[i]*p[i]>r)break;work(p[i]);}for(ans=i=0;i<=n;i++){if(f[i]>1)g[i]=1LL*g[i]*(k+1)%P;ans=(ans+g[i])%P;}printf("%d\n",ans);}return 0; }轉載于:https://www.cnblogs.com/pearfl/p/10733185.html
總結
以上是生活随笔為你收集整理的Counting Divisors HDU - 6069的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: rmReport 自适应行高(自动行高)
- 下一篇: Android_设备隐私获取,忽略6.0