日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【FZU - 1759】Super A^B mod C (数论,快速幂,快速乘,欧拉降幂,指数循环节,模板)

發布時間:2023/12/10 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【FZU - 1759】Super A^B mod C (数论,快速幂,快速乘,欧拉降幂,指数循环节,模板) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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

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 4 2 10 1000

Sample Output

1 24

解題報告:

? ?裸題,僅供模板準備。

AC代碼:

#include <iostream> #include <string.h> #include <stdio.h> using namespace std; const int N=1000005; typedef long long LL; char str[N]; int phi(int n) {int rea = n;for(int i=2; i*i<=n; i++) {if(n % i == 0) {rea = rea - rea / i;while(n % i == 0) n /= i;}}if(n > 1)rea = rea - rea / n;return rea; } LL multi(LL a,LL b,LL m) {LL ans = 0;a %= m;while(b) {if(b & 1) {ans = (ans + a) % m;b--;}b >>= 1;a = (a + a) % m;}return ans; } LL quick_mod(LL a,LL b,LL m) {LL ans = 1;a %= m;while(b) {if(b & 1) {ans = multi(ans,a,m);b--;}b >>= 1;a = multi(a,a,m);}return ans; } void Solve(LL a,char str[],LL c) {LL len = strlen(str);LL ans = 0;LL p = phi(c);if(len <= 15) {for(int i=0; i<len; i++)ans = ans * 10 + str[i] - '0';} else {for(int i=0; i<len; i++) {ans = ans * 10 + str[i] - '0';ans %= p;}ans += p;}printf("%I64d\n",quick_mod(a,ans,c)); } int main() {LL a,c;while(~scanf("%I64d%s%I64d",&a,str,&c))Solve(a,str,c);return 0; }

?

總結

以上是生活随笔為你收集整理的【FZU - 1759】Super A^B mod C (数论,快速幂,快速乘,欧拉降幂,指数循环节,模板)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。