牛客网 牛客小白月赛1 C.分元宵-快速幂

 

 
 
C.分元宵
 

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



这个题就是快速幂,注意特判,一开始忘了特判,wa了一发。

 

代码:

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<cmath>
 5 #include<cstdlib>
 6 #include<algorithm>
 7 using namespace std;
 8 typedef long long ll;
 9 ll mod;
10 ll kuaisumi(ll a,ll b){
11     ll ans=1;
12     while(b){ 13 if(b%2==1)ans=(ans*a)%mod; 14 a=(a*a)%mod; 15 b=b/2; 16  } 17 return ans; 18 } 19 int main(){ 20  ll a,b,c,d,ans; 21 cin>>a>>b>>c>>d>>mod; 22 if(a==0||b==0||c==0||d==0)ans=0; 23 else{ 24 ll p1=((a%mod)*(b%mod))%mod; 25 ll p2=c*d; 26 ans=kuaisumi(p1,p2); 27  } 28 cout<<ans<<endl; 29 }

 

转载于:https://www.cnblogs.com/ZERO-/p/9729000.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值