牛客暑期多校训练营B Basic Gcd Problem

在这里插入图片描述
在这里插入图片描述

题目大意:

给定 t 组数据,每组数据由一个n(下文中的x),一个c构成,计算分段函数
在这里插入图片描述
比赛的时候不认真看题,导致会错意了。。
比赛结束看了题解才明白
观察公式,fc(x) 其实是c 的若干次方,且指数要尽量大。最好的情况下,每次只消掉一个质因子。所以fc(x)=c^x的质因子个数


题目代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
using namespace std;
const long long mod=1e9+7;
int qpow(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b&1) res=1ll*res*a%mod;
        a=1ll*a*a%mod;
        b >>= 1;
    }
    return res;
}
int main()
{
    int t,x,c,f;
    long long ans;
    scanf("%d",&t);
    while(t--)
    {
        int cnt=0;
        ans=1;
        scanf("%d%d",&x,&c);
        if(x==1)
            cout<<1<<endl;
        else
        {
            int j;
            for(j=2;j*j<=x;j++)
            {
	             while(x%j==0)
	             {
	              x=x/j;
	              ans=(ans*c)%mod;
	    	     }
	    }
            if(x>1)
            	ans=(ans*c)%mod
            printf("%lld\n",ans);
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值