# 2020牛客暑期多校训练营（第九场） E.Groundhog Chasing Death(数论，质因数分解，费马小定理)

a ^ b % p == a ^ (b%(p-1)) % p

AC代码

#include <bits/stdc++.h>
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 2e3 + 5;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const int mod = 998244353;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
ll a,b,c,d,x,y,sum = 1;
ll quick_pow(ll a,ll b,ll p)
{
ll ans = 1;
while(b)
{
if(b&1)
ans = a*ans%p;
b>>=1;
a = a*a%p;
}
return ans;
}
void solve(ll num)
{
ll numa = 0,numb = 0,ans = 0;
while(x % num == 0) numa++,x/=num;
while(y % num == 0) numb++,y/=num;
if(numa == 0 || numb == 0) return ;
for(ll i = a;i <= b;i++)
{
ll j = numa*i/numb;
if(j < c) ans = ans + (d-c+1)*numa%(mod-1)*i%(mod-1);
else if(j >= d) ans = ans + (c+d)*(d-c+1)/2%(mod-1)*numb%(mod-1);
else ans = (ans + (d-j)*numa%(mod-1)*i%(mod-1) + (j+c)*(j-c+1)/2%(mod-1)*numb%(mod-1))%(mod-1);
ans %= (mod-1);
}
sum = sum*quick_pow(num,ans,mod)%mod;
}
signed main()
{
std::ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
cin >> a >> b >> c >> d >> x >> y;
for(ll i = 2;i * i <= x;i++)
if(x % i == 0)
solve(i);
if(x > 1) solve(x);
cout << sum << endl;
}


01-13

08-10 43