HDU 6069 Counting Divisors(2017 Multi-University Training Contest - Team 4 )

  

 

Output
For each test case, print a single line containing an integer, denoting the answer.
 

 

Sample Input
3 1 5 1 1 10 2 1 100 3
 

 

Sample Output
10 48 2302
 
 
题意:就是那个公式

 

感觉还是题解讲的清楚
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<cctype> 
 5 #include<cmath>
 6 #include<cstring>
 7 #include<map>
 8 #include<set>
 9 #include<queue>
10 #include<vector>
11 #include<algorithm>
12 #include<string> 
13 #define ll long long
14 #define eps 1e-10
15 #define LL unsigned long long
16 using namespace std; 
17 const int maxn=1000000+100;
18 const int mod=998244353;
19 int vis[maxn];
20 int prim[maxn];
21 ll a[maxn];
22 ll b[maxn];
23 int len;
24 void get_prim() 
25 {
26     memset(vis,0,sizeof(vis));
27     int m=sqrt(maxn+0.5);
28     for(int i=2;i<=m;i++)
29     if(vis[i]==0)
30     for(int j=i*i;j<=maxn;j+=i)
31     vis[j]=1;
32     len=0;
33     for(int i=2;i<=maxn;i++)
34     if(vis[i]==0)
35     prim[len++]=i;
36 }
37 int main()
38 {
39     int t;
40     ll l,r,k;
41     get_prim();
42     scanf("%d",&t);
43     while(t--)
44     {
45         scanf("%lld%lld%lld",&l,&r,&k);
46         for(int i=0;i<maxn;i++)
47         {
48           a[i]=1;
49           b[i]=i+l;
50         }
51           for(int i=0;i<len;i++)
52           {
53               ll cnt=l;
54             if(l%prim[i])cnt=l+prim[i]-l%prim[i];
55               for(ll j=cnt;j<=r;j+=prim[i])
56               {
57                   int count=0;
58                   while(b[j-l]%prim[i]==0)
59                   {
60                       count++;
61                       b[j-l]/=prim[i];
62                 }
63                 a[j-l]=((k*count+1)%mod*a[j-l])%mod;
64               }
65           }
66           ll ans=0;
67           for(int i=0;i<=r-l;i++)
68           if(b[i]>1)
69           a[i]=(a[i]*(k+1))%mod;
70           for(int i=0;i<=r-l;i++)
71           {
72               ans=(ans+a[i])%mod;
73           }
74           printf("%lld\n",ans);
75     }
76     return 0;
77 }

 

 

posted on 2017-08-03 22:59  见字如面  阅读(192)  评论(0编辑  收藏  举报

导航