cf C. Prime Number

http://codeforces.com/contest/359/problem/C

先求出分子的公因子,然后根据分子上会除以公因子会长生1,然后记录1的个数就可以。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define maxn 200000
 5 #define LL __int64
 6 using namespace std;
 7 
 8 LL a[maxn];
 9 LL n,x;
10 LL min1(LL s,LL d)
11 {
12     if(s>d)return d;
13     return s;
14 }
15 
16 LL pow_mod(LL a,LL p,LL m)//快速幂取模
17 {
18     if(p==0) return 1;
19     LL ans1=pow_mod(a,p/2,m);
20     ans1=ans1*ans1%m;
21     if(p%2==1) ans1=ans1*a%m;
22     return ans1;
23 }
24 
25 int main()
26 {
27     while(scanf("%I64d%I64d",&n,&x)!=EOF)
28     {
29         LL sum=0;
30         for(int i=1; i<=n; i++)
31         {
32             scanf("%I64d",&a[i]);
33             sum+=a[i];
34         }
35         LL ans=sum-a[n];//分子中最小公因子
36         LL c=a[n];
37         int t1=0;//记录可以产生1的个数
38         int pos=n;
39         while(c>=1)
40         {
41             while(a[pos]==c&&pos>=1)
42             {
43                 pos--;
44                 t1++;
45             }
46             c--;
47             if(t1%x==0)
48             {
49                 ans++;
50                 t1/=x;
51             }
52             else
53                 break;
54         }
55         ans=min1(ans,sum);
56         printf("%I64d\n",pow_mod(x,ans,1000000007));
57     }
58     return 0;
59 }
View Code

 

转载于:https://www.cnblogs.com/fanminghui/p/3938253.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值