FOJ ——Problem 1759 Super A^B mod C
Problem 1759 Super A^B mod CAccept: 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 ...
随机推荐
- 图像压缩函数imagecopyresampled
<?php //制作缩略图.图像压缩 //参数1:目的地图像资源(通常指的是画布资源) $dst_image = imagecreatetruecolor(100, 100); $color = ...
- 多通道CNN
在读Convolutional Neural Networks for Sentence Classification 这个文章的时候,它在论文中提出一种模型变种就是 CNN-multichannel ...
- Java实现系统目录实时监听更新。
SDK1.7新增的nio WatchService能完美解决这个问题.美中不足是如果部署在window系统下会出现莫名其妙的文件夹占用异常导致子目录监听失效,linux下则完美运行.这个问题着实让人头 ...
- dubbo本地搭建实例
项目文件下载地址:http://download.csdn.net/detail/aqsunkai/9552711 概述 Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服 ...
- android gesture检测
1.关于on<TouchEvent>的返回值 a return value of true from the individual on<TouchEvent> methods ...
- ARC下还会存在内存泄露吗?
1.第三方框架不正当使用.2.block,delegate,NSTimer循环使用.3.非oc对象的内存处理.4.地图类处理.5.大次数循环内存暴涨. 非oc对象的释放: 例如使用CGImageRel ...
- 《Cracking the Coding Interview》——第8章:面向对象设计——题目4
2014-04-23 18:17 题目:设计一个停车位的类. 解法:停车位,就要有停车.取车的功能了.另外我还加了一个工作线程用于计费,每秒给那些有车的车位加1块钱费用. 代码: // 8.4 Des ...
- 《算法》C++代码 SPFA
SPFA的全称是Shortest Path Faster Algorithm,一看名称八成就是中国人起的名字,因为外国人起算法名称一般都会写上自己的名字,很少谦虚.实际上,这是西南交通大学段凡丁同学于 ...
- 抓取网站访问者的QQ号码
开源,是一种精神.但不开源,并不是没有精神,而可能是代码写得惨不忍睹,我属于后者.(首先申明:对代码提出意见可接受,虚心接受,但不能人身攻击啊!) 最近闲的蛋疼,喜欢到处看看做得好的站点, 莫 ...
- 每天一个Linux命令(5):rm命令
rm命令可以删除一个目录中的一个或多个文件或目录,也可以将某个目录及其下属的所有文件及其子目录均删除掉.对于链接文件,只是删除整个链接文件,而原有文件保持不变. 语法 rm (选项)(参数) 选项 - ...