Problem 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

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
思路:指数循环节,数据水,并没有B<C&&A,C不互质的;
#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 指数循环节的更多相关文章

  1. 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 ...

  2. fzou 1759 Super A^B mod C

    Problem 1759 Super A^B mod CAccept: 456    Submit: 1488Time Limit: 1000 mSec    Memory Limit : 32768 ...

  3. 【转】【关于 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 ...

  4. UVA 10692 Huge Mods(指数循环节)

    指数循环节,由于a ^x = a ^(x % m + phi(m)) (mod m)仅在x >= phi(m)时成立,故应注意要判断 //by:Gavin http://www.cnblogs. ...

  5. FZU:1759-Problem 1759 Super A^B mod C (欧拉降幂)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759 欧拉降幂是用来干啥的?例如一个问题AB mod c,当B特别大的时候int或者longlong装不下的时 ...

  6. FZU-1759 Super A^B mod C---欧拉降幂&指数循环节

    题目链接: https://cn.vjudge.net/problem/FZU-1759 题目大意: 求A^B%C 解题思路: 注意,这里long long需要用%I64读入,不能用%lld #inc ...

  7. bzoj 3884 上帝与集合的正确用法 指数循环节

    3884: 上帝与集合的正确用法 Time Limit: 5 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description   根据一些 ...

  8. Codeforces Beta Round #17 D.Notepad 指数循环节

    D. Notepad time limit per test 2 seconds memory limit per test 64 megabytes input standard input out ...

  9. 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 ...

随机推荐

  1. less-!important关键字

    //!important关键字 使用!important关键字混入调用之后,以标记它继承的所有属性!important,example: .test{ background:red; font-siz ...

  2. Android编译系统入门(一)

    做过Android平台开发的朋友对make,mm或make clean命令应该很熟悉,但也许大家只是熟知这些命令的作用却不知道这些命令底下有些什么原理?那么今天我就带着大家推开Android编译系统的 ...

  3. delphi =------报错

    关于delphi软件运行出现Invalid floating point operation的错误的解决办法 关于delphi软件运行出现Invalid floating point operatio ...

  4. apktool 工具

      下载 https://code.google.com/p/android-apktool/ apktool_2.0.0rc2.jar 和apktool linux脚本 ln –s apktool_ ...

  5. Tika a content analysis toolkit

    Apache Tika - a content analysis toolkit The Apache Tika™ toolkit detects and extracts metadata and ...

  6. CSRF Cross-site request forgery

    w 跨站请求伪造目标站---无知用户---恶意站 http://fallensnow-jack.blogspot.com/2011/08/webgoat-csrf.html https://wiki. ...

  7. HTTP 常见状态码

    1. 以"1"开头(临时响应) 100: Continue,请求者应当继续提出请求;表示服务端已经收到请求的一部分,正在等待其余部分; 101: Switching Protoco ...

  8. mysql 中sum (if())与case

    先来一个简单的sum select sum(qty) as total_qty from inventory_product group by product_id 这样就会统计出所有product的 ...

  9. golang 实现并发计算文件数量

    package main import ( "fmt" "io/ioutil" "os" ) func listDir(path strin ...

  10. Library Cache优化与SQL游标

    Library Cache主要用于存放SQL游标,而SQL游标最大化共享是Library Cache优化的重要途径,可以使SQL运行开销最低.性能最优. 1 SQL语句与父游标及子游标 在PL/SQL ...