FZU 1759 Super A^B mod C 指数循环节
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
Sample Output
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll __int64
#define esp 0.00000000001
const int N=1e5+,M=1e6+,inf=1e9+;
const int mod=;
#define MAXN 10000010
ll quickpow(ll x,ll y,ll z)
{
ll ans=;
while(y)
{
if(y&)
ans*=x,ans%=z;
x*=x;
x%=z;
y>>=;
}
return ans;
}
ll phi(ll n)
{
ll i,rea=n;
for(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;
}
char a[M];
int main()
{
ll x,y,z,i,t;
while(~scanf("%I64d%s%I64d",&x,a,&z))
{
t=strlen(a);
ll p=phi(z);
ll ans=;
for(i=;i<t;i++)
ans=(ans*+a[i]-'')%p;
ans+=p;
printf("%I64d\n",quickpow(x,ans,z));
}
return ;
}
FZU 1759 Super A^B mod C 指数循环节的更多相关文章
- FOJ ——Problem 1759 Super A^B mod C
Problem 1759 Super A^B mod C Accept: 1368 Submit: 4639Time Limit: 1000 mSec Memory Limit : 32 ...
- fzou 1759 Super A^B mod C
Problem 1759 Super A^B mod CAccept: 456 Submit: 1488Time Limit: 1000 mSec Memory Limit : 32768 ...
- 【转】【关于 A^x = A^(x % Phi(C) + Phi(C)) (mod C) 的若干证明】【指数循环节】
[关于 A^x = A^(x % Phi(C) + Phi(C)) (mod C) 的若干证明][指数循环节] 原文地址:http://hi.baidu.com/aekdycoin/item/e493 ...
- UVA 10692 Huge Mods(指数循环节)
指数循环节,由于a ^x = a ^(x % m + phi(m)) (mod m)仅在x >= phi(m)时成立,故应注意要判断 //by:Gavin http://www.cnblogs. ...
- 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-1759 Super A^B mod C---欧拉降幂&指数循环节
题目链接: https://cn.vjudge.net/problem/FZU-1759 题目大意: 求A^B%C 解题思路: 注意,这里long long需要用%I64读入,不能用%lld #inc ...
- bzoj 3884 上帝与集合的正确用法 指数循环节
3884: 上帝与集合的正确用法 Time Limit: 5 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description 根据一些 ...
- Codeforces Beta Round #17 D.Notepad 指数循环节
D. Notepad time limit per test 2 seconds memory limit per test 64 megabytes input standard input out ...
- hdu_2837_Calculation(欧拉函数,快速幂求指数循环节)
Assume that f(0) = 1 and 0^0=1. f(n) = (n%10)^f(n/10) for all n bigger than zero. Please calculate f ...
随机推荐
- 指定文件夹 指定文件后缀名 删除整个文件夹 git 冲突解决 create a new repository on the command line push an existing repository from the command line
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001375840038939c2 ...
- nodejs unit test related----faker-cli, sinonjs, mock/stub
http://www.tuicool.com/articles/rAnaYvn http://www.tuicool.com/articles/Y73aYn (contrast stub and mo ...
- time/datetime/random/string/os/sys/shutil/zipfile/tarfile - 总结
time 模块: time.time() #时间戳 time.localtime() #当前时间对象元组 time.localtime(123123) #根据时间戳的时间对象 time.mktime( ...
- MongoDB-6: MongoDB索引
一.简介 在MongoDB建立索引能提高查询效率,只需要扫描索引只存储的这个集合的一小部分,并只把这小部分加载到内存中,效率大大的提高,如果没有建立索引,在查询时,MongoDB必须执行全表扫描,在数 ...
- python列表套字典数据类型转换
1.题目 list3 = [ {'name':'Alex','hobby':'抽烟'}, {'name':'Alex', 'hobby':'喝酒'}, {'name':'Alex', 'hobby': ...
- Codeforces Round#251(Div 2)D Devu and his Brother
--你以为你以为的.就是你以为的? --有时候还真是 题目链接:http://codeforces.com/contest/439/problem/D 题意大概就是要求第一个数组的最小值要不小于第二个 ...
- golang 常用的日期方法和时区的坑
import( "time" ) 1.获取当前时间 time.Now(),返回类型:time结构. 2.字符串转为日期 t, _ := time.ParseInLocation(& ...
- RTSP客户端接收存储数据(live555库中的testRTSPClient实例)
1.testRTSPClient简介 testRTSPClient是个简单的客户端实例,这个实例对rtsp数据交互作了详细的描述,其中涉及到rtsp会话的两个概念Source和Sink. Source ...
- python中self cls init的理解
原创文章,未经允许禁止转载! python中self cls init的理解 python中self cls init的理解
- day4 字符串的使用方法
一.字符串切片 索引和切片 [起始位置:结束位置:步长] s1 = 'python全栈8期' # 索引从0开始[索引(下标,index)] print(s1[0]) print(s1[3]) prin ...