Codeforces 209 div2 C. Prime Number

本文提供了一道名为C.PrimeNumber的编程题的解答思路与实现代码。该题通过求最小公因数来简化问题,并利用while循环来判断是否可以进一步提取公因式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目:C. Prime Number

思路:通分之后,分母是x^sum,分子是sigma(x^(sum-a[i])),首先能提取的公因式是min(x^(sum-a[i])),对于剩下的,看产生的1能不能形成ax的形式,while搞定

 tag :暴力


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long LL;
LL mod=LL(1e9+7);
#define maxn 100010
int num[maxn];
LL Pow(LL a,LL b)
{
    LL ans=1;
    while(b)
    {
        if(b&1)
        {
            b--;
            ans=(ans*a)%mod;
        }
        else
        {
            b/=2;
            a=(a*a)%mod;
        }
    }
    return ans;
}
int main()
{
    LL n,x;
    scanf("%I64d%I64d",&n,&x);
    LL sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&num[i]);
        sum+=num[i];
    }
    int index=n;
    long long ans=sum-num[n];
    int p=num[n];
    int tmp=0;
    while(p>=1)
    {
        while(num[index]==p && index>=1)
        {
            index--;
            tmp++;
        }
        p--;
        if(tmp%x==0)
        {
            ans++;
            tmp/=x;
        }
        else
            break;
    }
    ans=min(ans,sum);
    printf("%I64d\n",Pow(x,ans));
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值