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. Spoken English Practice(Look, That cute guy is checking me out. come on, give me a break, he's just looking around.)

    绿色:连读:                  红色:略读:               蓝色:浊化:               橙色:弱读     下划线_为浊化 口语蜕变(2017/7/6) 英 ...

  2. dist\_wepylogs.js

    console.log('WePY开启错误监控'); console.warn("CLI报错:WARNING IN : src\pages\cloundAd.vue\n[xmldom war ...

  3. 阻塞IO 非阻塞IO 异步IO

    阻塞IO 一般表现为 进程/线程 调用IO操作后就一直死循环等待,直至IO操作结束,返回IO结果 非阻塞IO 一般表现为 进程/线程 调用IO操作后,可以先去干别的事情,但是每隔一段时间,回去询问一下 ...

  4. DRF(2) - 解析器,序列化组件使用(GET/POST接口设计)

    一.DRF - 解析器 1.解析器的引出 我们知道,浏览器可以向django服务器发送json格式的数据,此时,django不会帮我们进行解析,只是将发送的原数据保存在request.body中,只有 ...

  5. Using Swift with Cocoa and Objective-C--在同个project中使用Swift和在同个project中

    http://www.cocoachina.com/newbie/basic/2014/0605/8688.html watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5u ...

  6. 配置YARN

    1.配置yarn-site.xml(所有节点) 路径: /usr/local/hadoop-2.7.3/etc/hadoop/yarn-site.xml 配置项: <property> & ...

  7. 信息安全意识教育日历——By 安全牛

    安全牛:企业即使投入再好的信息安全技术和产品,也难以解决内部威胁以及社会工程等攻击手段,无法做到全面有效地保护企业信息资产.而通过开展员工的信息安全意识培训教育工作,不仅能降低企业风险.满足合规要求, ...

  8. Erlang正则解析操作文件

    -module(tool). %% ==================================================================== %% API functi ...

  9. 012-JDK可视化监控工具-jstack

    一.概述 jstack是java虚拟机自带的一种堆栈跟踪工具.jstack用于打印出给定的java进程ID或core file或远程调试服务的Java堆栈信息,如果是在64位机器上,需要指定选项&qu ...

  10. Hurst指数以及MF-DFA

    转:https://uqer.io/home/ https://uqer.io/community/share/564c3bc2f9f06c4446b48393 写在前面 9月的时候说想把arch包加 ...