FOJ ——Problem 1759 Super A^B mod C

Accept: 1368 Submit: 4639
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,C<=1000000000,1<=B<=10^1000000).
Input
Output
Sample Input
2 10 1000
Sample Output
24

求出c的欧拉函数,最后再求快速幂,就可以得到long long范围内的结果了
tips:FOJ不支持万能头文件和%lld
http://acm.fzu.edu.cn/problem.php?pid=1759
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=1e6+;
typedef long long ll;
char str[maxn];
int phi(int n){
int rea=n;
for(int i=;i*i<=n;i++){
if(n%i==){
rea=rea-rea/i;
while(n%i==) n/=i;
}
}
if(n>) rea=rea-rea/n;
return rea;
}
ll multi(ll a,ll b,ll m){
ll ans=;
a%=m;
while(b){
if(b&){
ans=(ans+a)%m;
b--;
}
b>>=;
a=(a+a)%m;
}
return ans;
} ll quick_mod(ll a,ll b,ll m){
ll ans=;
a%=m;
while(b){
if(b&){
ans=multi(ans,a,m);
b--;
}
b>>=;
a=multi(a,a,m);
}
return ans;
}
void solve(ll a,char str[],ll c){
ll len=strlen(str);
ll ans=;
ll p=phi(c);
if(len<=){
for(int i=;i<len;i++){
ans=ans*+str[i]-'';
}
}else{
for(int i=;i<len;i++){
ans=ans*+str[i]-'';
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 ;
}
FOJ ——Problem 1759 Super A^B mod C的更多相关文章
- fzou 1759 Super A^B mod C
Problem 1759 Super A^B mod CAccept: 456 Submit: 1488Time Limit: 1000 mSec Memory Limit : 32768 ...
- FZU 1759 Super A^B mod C 指数循环节
Problem 1759 Super A^B mod C Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description G ...
- FZU:1759-Problem 1759 Super A^B mod C (欧拉降幂)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759 欧拉降幂是用来干啥的?例如一个问题AB mod c,当B特别大的时候int或者longlong装不下的时 ...
- FZU Super A^B mod C(欧拉函数降幂)
Problem 1759 Super A^B mod C Accept: 878 Submit: 2870 Time Limit: 1000 mSec Memory Limit : 327 ...
- Day7 - B - Super A^B mod C FZU - 1759
Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B ...
- Super A^B mod C (快速幂+欧拉函数+欧拉定理)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759 题目:Problem Description Given A,B,C, You should quick ...
- foj Problem 2107 Hua Rong Dao
Problem 2107 Hua Rong Dao Accept: 503 Submit: 1054Time Limit: 1000 mSec Memory Limit : 32768 K ...
- foj Problem 2282 Wand
Problem 2282 Wand Accept: 432 Submit: 1537Time Limit: 1000 mSec Memory Limit : 262144 KB Prob ...
- FOJ Problem 2273 Triangles
Problem 2273 Triangles Accept: 201 Submit: 661Time Limit: 1000 mSec Memory Limit : 262144 KB P ...
随机推荐
- Shell学习——数值运算
在Bash shell中,可以利用let.(( )).[]执行基本的算术操作,在高级操作时,使用expr和bc两个工具1.let[root@client02 ~]# no1=4[root@client ...
- scrapy--matplotlib
昨天晚上看了一些关于保存文件的相关资料,早早的睡了,白天根据网上查找的资料,自己再捡起来.弄了一上午就爬取出来了,开心!!!好吧,让我们开始 老规矩,先上图.大家也赶快行动起来 分类文件: 文件内co ...
- hosts 文件的位置及作用
一.位置 1.Window系统位置 C:\Windows\System32\drivers\etc 2.Linux系统位置 /etc/hosts 二.作用 综述:Hosts文件中指定了域名和IP地址的 ...
- POJ 1981 最大点覆盖问题(极角排序)
Circle and Points Time Limit: 5000MS Memory Limit: 30000K Total Submissions: 8346 Accepted: 2974 ...
- 笔记-Python-language reference-5.the import system
笔记-Python-language reference-5.the import system 前言 经常用到import,module,对其中的机制及原理有一定的了解,但没有将各种信息前后连通起来 ...
- com.squareup.okhttp.Interceptor
retrift 集成了okhttp,所以,我们以后就不用再单独的引用http的jar 了. 但是,今天遇到一个问题,就是okhttp是这样设置一些intercept的: private static ...
- Div处理滚动条问题
1,用div做容器现在已经十分普遍,下面是最基本的代码 <div style="width:50px;height:50px;background-color:blue"&g ...
- 腾讯云分析MTA HTML5接入方法
从微信服务号或订阅号里跳转到自己项目后,想在项目中统计出实时数据.历史趋势.实时访客.新老访客比.访客画像.地域信息.运营商.终端信息.页面排行.性能监控.访问深度.外部链接.入口页面.离开页面.渠道 ...
- 如何使用malloc申请一个二位数组
fscanf(file, "%d", &iVertexNum); // Read number of Vertices double **G = (double **)ma ...
- 让NVelocity做更多的事,VS Extension+NVelocity系列
我不知道园子里到底有多少人喜欢使用NVelocity这个模板引擎,其实说实话,如果现在让我选,我对Razor的喜好要比NVelocity或者T4等等的模板引擎更多一些,当然了,个人看法而已.只是我在公 ...