https://ac.nowcoder.com/acm/contest/5674/E

  质因数分解+数学+费马小定理

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const int maxx = 3e6+10;
 5 const int mod = 998244353;
 6 const int phi = mod-1;
 7 struct node1
 8 {
 9     LL x,num;
10 }p1[1000],p2[1000];
11 struct node2
12 {
13     LL x,d1,d2;
14 }p[1000];
15 LL quick(LL a,LL b)
16 {
17     LL res=1;
18     while(b)
19     {
20         if(b&1)res=res*a%mod;
21         a=a*a%mod;
22         b>>=1;
23     }
24     return res;
25 }
26 int main()
27 {
28     ios::sync_with_stdio(false);
29     LL a,b,c,d,x,y;
30     cin>>a>>b>>c>>d>>x>>y;
31     int t1=0,t2=0;
32     for(int i=2;i*i<=x;i++)
33     {
34         if(x%i)continue;
35         int num=0;
36         while(x%i==0)x/=i,num++;
37         p1[++t1]=node1{i,num};
38     }
39     if(x>1)p1[++t1]=node1{x,1};
40     for(int i=2;i*i<=y;i++)
41     {
42         if(y%i)continue;
43         int num=0;
44         while(y%i==0)y/=i,num++;
45         p2[++t2]=node1{i,num};
46     }
47     if(y>1)p2[++t2]=node1{y,1};
48     int num=0;
49     for(int i=1;i<=t1;i++)
50         for(int j=1;j<=t2;j++)
51         {
52             if(p1[i].x==p2[j].x)
53             {
54                 p[++num]=node2{p1[i].x,p1[i].num,p2[j].num};
55             }
56         }
57     LL ans=1;
58     for(int i=1;i<=num;i++)
59     {
60         LL res=0;
61         for(int j=a;j<=b;j++)
62         {
63             LL tmp=p[i].d1*j/p[i].d2;
64             tmp=min(tmp,d);
65             if(tmp>=c)
66             {
67                 LL sum=(tmp+c)*(tmp-c+1)/2;
68                 sum%=phi;
69                 sum=sum*p[i].d2%phi;
70                 res=(res+sum)%phi;
71             }
72             tmp=max(tmp+1,c);
73             if(tmp<=d)
74             {
75                 LL sum=d-tmp+1;
76                 sum%=phi;
77                 sum=sum*p[i].d1%phi*j%phi;
78                 res=(res+sum)%phi;
79             }
80         }
81         ans=ans*quick(p[i].x,res)%mod;
82     }
83     cout<<ans<<endl;
84     return 0;
85 }

 

posted @ 2020-08-11 11:54  古比  阅读(308)  评论(0编辑  收藏  举报