FZU 1759-Super A^B mod C(快速幂+大整数取模+欧拉函数)
来源:互联网 发布:mac chrome插件导出 编辑:程序博客网 时间:2024/05/18 03:28
题目链接:点击打开链接
题意:计算 a^b %c 但其中b很大,可能会达到10^1000000, 故有降幂公式 a^b %c= a^(b%phi(c)+phi(c)) %c (b>=phi(c))
#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>#include <string>#include <cctype>#include <vector>#include <cstdio>#include <cmath>#include <queue>#include <stack>#include <map>#include <set>#define maxn 10100#define _ll __int64#define ll long long#define INF 0x3f3f3f3f#define Mod 1000000007#define pp pair<int,int>#define ull unsigned long longusing namespace std;int a,c;char b[1000010];ll phi(ll n){ll m=(ll)sqrt(n+0.5),ans=n;for(ll i=2;i<=m;i++){if(n%i==0){ans=ans/i*(i-1);while(n%i==0)n/=i;}}if(n>1)ans=ans/n*(n-1);return ans;}ll pow_mod(ll a,ll n,ll p){if(n==0)return 1;ll ans=pow_mod(a,n/2,p);ans=ans*ans%p;if(n&1)ans=ans*a%p;return ans;}void solve(){int len=strlen(b);ll tem=phi(c),sb;if(len<=10){sscanf(b,"%I64d",&sb);if(sb>=tem)printf("%I64d\n",pow_mod(a,sb%tem+tem,c));elseprintf("%I64d\n",pow_mod(a,sb,c));return ;}ll ans=0;for(int i=0;i<len;i++)ans=(ans*10+(b[i]-'0'))%tem;printf("%I64d\n",pow_mod(a,ans+tem,c));}int main(){while(~scanf("%I64d %s %I64d",&a,b,&c))solve(); return 0;}
1 0
- FZU 1759-Super A^B mod C(快速幂+大整数取模+欧拉函数)
- FZU 1759 Super A^B mod C (欧拉函数,快速幂,降幂公式)
- FZU 1759 Super A^B mod C(数论+快速幂+欧拉函数)
- FZU oj 1759 Super A^B mod C (快速幂+指数循环节+欧拉函数)
- FZU 1759-Super A^B mod C (快速幂+欧拉降幂+欧拉函数)
- fzu Problem 1759 Super A^B mod C(快速幂取模+欧拉函数)
- FZU 1759-Super A^B mod C (欧拉函数+降幂公式)
- FZU 1759 Super A^B mod C (欧拉函数,降幂公式)
- FZU 1759 Super A^B mod C (超级快速幂)
- 欧拉函数 FZOJ 1759 Super A^B mod C
- Super A^B mod C 快速幂+欧拉函数降幂
- FZU1759 Super A^B mod C 欧拉函数+快速幂+公式
- fzu1759 Super A^B mod C 【欧拉函数应用+快速幂】
- FZU 1759 Super A^B mod C
- FZU 1759Super A^B mod C
- FZU-1759 Super A^B mod C
- FZU 1759 Super A^B mod C
- FZU - 1759 Super A^B mod C 降幂公式
- js 中的trim用replace实现IE8不支持trim
- 链表(12)----判断是否有环,如果有环,判断是6型环,还是0型环
- 删除.svn文件的代码
- 持续集成可视化 RSS
- Invalid location of tag 解决办法分析
- FZU 1759-Super A^B mod C(快速幂+大整数取模+欧拉函数)
- LEETCODE: Letter Combinations of a Phone Number
- 第16周oj项目4输出奇数因子
- mysql中distinct去除重复值方法
- JSP传值后台乱码解决
- 【CUDA并行编程之四】矩阵相乘
- LeetCode 3sum
- excel 统计一个区域的内容是否完全在另一个区域内。
- maven myeclipse10 整合开发web项目-3