1. 程式人生 > 實用技巧 >牛客網Groundhog and Gaming Time

牛客網Groundhog and Gaming Time

連結:https://ac.nowcoder.com/acm/contest/5674/C
來源:牛客網

題目描述:

分析:

程式碼如下:

#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353;
int u,v,ans;
int Pow(int x,int y)
{
    if(!y) return 1;
    int z=Pow(x,y>>1);
    z=1ll*z*z%mod;
    if(y&1) z=1ll*z*x%mod;
    return
z; } int get(int x,int y) { int z=0,i,j; for(int i=1;i<=x;i++) { j=u*i/v; if(j>y) j=y; z=(z+(j+1LL)*j/2%(mod-1)*v)%(mod-1); z=(z+1LL*i*(y-j)%(mod-1)*u)%(mod-1); } return z; } int main() { int a,b,c,d,x,y,z,m,i; scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&x,&y); ans
=1; m=max(x,y); for(int i=2; i*i<=max(x,y); i++) { u=v=0; while(x%i==0) { u++; x/=i; } while(y%i==0) { v++; y/=i; } if (!u || !v) continue; z=(2ll*(mod-1)+get(b,d)+get(a-1
,c-1)-get(a-1,d)-get(b,c-1))%(mod-1); ans=1ll*ans*Pow(i,z)%mod; } if(x>1 && x==y) { u=v=1; z=(2ll*(mod-1)+get(b,d)+get(a-1,c-1)-get(a-1,d)-get(b,c-1))%(mod-1); ans=1ll*ans*Pow(x,z)%mod; } printf("%d",ans); }
View Code