标签:质因数分解 get com using mission hdu problem false string
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 2599 Accepted Submission(s): 959
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<cmath> 5 #include<stdio.h> 6 #define it (p-l) 7 using namespace std; 8 typedef long long LL; 9 const LL MOD=998244353; 10 const long long MAXN=1000005; 11 long long prime[MAXN],tot=0; 12 bool isPrime[MAXN]; 13 LL k,num[MAXN],res[MAXN]; 14 void getprime(){ 15 memset(isPrime, true, sizeof(isPrime)); 16 for(int i=2;i<MAXN;i++){ 17 if(isPrime[i]){ 18 prime[++tot]=i; 19 } 20 for(int j=1;j<=tot;j++){ 21 if(i*prime[j]>MAXN) break; 22 isPrime[i*prime[j]]=false; 23 if(i%prime[j]==0) break; 24 } 25 } 26 return ; 27 } 28 LL cal(LL l, LL r) 29 { 30 LL ans=0,tmp,cnt; 31 for(int i=1;i<=tot;i++) 32 { 33 LL p=(l+prime[i]-1)/prime[i]*prime[i]; 34 while(p<=r){ 35 cnt=0; 36 while(num[it]%prime[i]==0){ 37 num[it]/=prime[i]; 38 cnt++; 39 } 40 res[it]=res[it]*(k*cnt+1)%MOD; 41 p+=prime[i]; 42 } 43 } 44 for(LL p=l;p<=r;p++){ 45 if(num[it]==1) 46 ans+=res[it]; 47 else 48 ans+=res[it]*(k+1); 49 ans%=MOD; 50 } 51 return ans; 52 } 53 int main() 54 { 55 int T; 56 LL l,r; 57 getprime(); 58 scanf("%d", &T); 59 while(T--) 60 { 61 scanf("%lld %lld %lld", &l, &r, &k); 62 for(LL p=l;p<=r;p++){ 63 res[it]=1; 64 num[it]=p; 65 } 66 LL res=cal(l, r); 67 printf("%lld\n", res); 68 } 69 }
HDU 6069 Counting Divisors —— 2017 Multi-University Training 4
标签:质因数分解 get com using mission hdu problem false string
原文地址:http://www.cnblogs.com/MasterSpark/p/7291193.html