国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

FZU 1752 A^B mod C (快速冪+快乘)

2019-11-08 01:40:14
字體:
來源:轉載
供稿:網友
Time Limit: 1000 mSec    Memory Limit : 32768 KB

PRoblem Description

Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,B,C<2^63).

Input

There are multiply testcases. Each testcase, there is one line contains three integers A, B and C, separated by a single space.

Output

For each testcase, output an integer, denotes the result of A^B mod C.

Sample Input

3 2 42 10 1000

Sample Output

124

Source

FZU 2009 Summer Training IV--Number Theory

為了防止相乘溢出,所以就用加減來實現,此外這個oj不支持%lld 我在這里也出錯了幾次,大家要注意哦 ??!

#include<stdio.h>using namespace std;#define ll long longll mulmod(ll a,ll b,ll c){    ll ans=0;    while(b)    {        if(b&1)        {            ans+=a;            if(ans>=c) ans-=c;        }        a<<=1;        if(a>=c)  a-=c;        b>>=1;    }    return ans;}ll quickmod(ll a,ll b,ll c){    ll ans=1;    while(b)    {        if(b&1)           ans=mulmod(ans,a,c);//這樣寫是為了使a*ans和a*a不溢出        a=mulmod(a,a,c);        b>>=1;    }    return ans;}int main(){    ll a,b,c ;    while(~scanf("%I64d%I64d%I64d",&a,&b,&c))    {        a=a%c;        printf("%I64d/n",quickmod(a,b,c));    }    return  0;}


上一篇:C# combox1控件的應用

下一篇:n a^o7 !

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 普定县| 娱乐| 寻乌县| 壤塘县| 从化市| 东乡族自治县| 集安市| 宁德市| 合山市| 玉屏| 叶城县| 红桥区| 当雄县| 芦山县| 错那县| 吐鲁番市| 盖州市| 白沙| 宜城市| 沙河市| 仙桃市| 河间市| 松溪县| 旺苍县| 五家渠市| 道真| 巴青县| 桑植县| 南澳县| 炎陵县| 陕西省| 吉木萨尔县| 新田县| 微山县| 安图县| 巨野县| 平罗县| 岳普湖县| 惠安县| 高安市| 石林|