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. CodeFores 665D Simple Subset(贪心)

    D. Simple Subset time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  2. 8.javascript获取表单中两个数字,并判断大小

    获取表单数据的方式: 1.表单注意些id 2.使用document.getElementById("num").value 获取值 3.一定要注意现在得到是string类型,可以用 ...

  3. amazonservices api 抽象类 Class Abstraction

    http://php.net/manual/zh/language.oop5.abstract.php MWSOrdersPHPClientLibrary-2013-09-01._V533357711 ...

  4. 码云平台, Git提交需要输入用户名/密码, 怎么办

    这是因为, 检出代码的时候, 使用了http的方式: 那么, 改为ssh的地址就行了

  5. Python计算地图上两点经纬度间的距离

    处理地图数据时,经常需要用到两个地理位置间的距离.比如A点经纬度(110.0123, 23.32435),B点经纬度(129.1344,25.5465),求AB两点之间的距离.我们可以用haversi ...

  6. Java中native关键字使用

    native是与C++异构开发的时候用的.java自己开发不会使用

  7. Spring MVC 框架结构介绍(二)

    Spring MVC框架结构 Spring MVC是围绕DispatcherServlet设计的,DispatcherServlet向处理程序分发各种请求.处理程序默认基于@Controller和@R ...

  8. Java 之多线程通信(等待/唤醒)

    多线程间通信: 多个线程在处理同一个资源, 但是任务却不同. 等待/唤醒机制 涉及的方法 wait(): 让线程处于冻结状态, 被 wait() 的线程会被存储到线程池中 notify(): 唤醒线程 ...

  9. linkText()的用法

    1.linkText()常用于定位链接,以谷歌的gmail为例: WebElement gmailLink = driver.findElement(By.linkText("Gmail&q ...

  10. mysql 内置功能 函数 date_format函数

    创建数据库db12 create database db12 charset=utf8; use db12; 准备表和记录 CREATE TABLE blog ( id INT PRIMARY KEY ...