牛客网Groundhog and Gaming Time

链接:https://ac.nowcoder.com/acm/contest/5674/C
来源:牛客网

题目描述:

 

分析:

牛客网Groundhog and Gaming Time_第1张图片

 

代码如下:

#include
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

 

你可能感兴趣的:(牛客网Groundhog and Gaming Time)