本题考点:欧拉降幂

Super A^B mod C

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
23
分析:欧拉降幂的模板题
直接套公式即可:

AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
ll a,p;
char b[];
ll phi(ll x)
{
ll res=x;
ll a=x;
for(int i=;i*i<=x;i++)
{
if(a%i==)
{
res=res/i*(i-);
while(a%i==) a/=i;
}
}
if(a>) res=res/a*(a-);
return res;
}
ll qp(ll a,ll b,ll p)
{
ll ans=;
while(b)
{
if(b&)
{
ans=(ans*a)%p;
}
a=(a*a)%p;
b>>=;
}
return ans;
}
int main()
{
//freopen("input.txt","r",stdin);
while(scanf("%lld %s %lld",&a,&b,&p)!=EOF)
{
ll len=strlen(b);
ll res=;
ll pp=phi(p);
for(int i=;i<len;i++)
{
res=(res*+b[i]-'')%pp;
}
printf("%lld\n",qp(a,res,p));
}
return ;
}

FZU 1759 题解 欧拉降幂的更多相关文章

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

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

  2. bzoj3884: 上帝与集合的正确用法 欧拉降幂公式

    欧拉降幂公式:http://blog.csdn.net/acdreamers/article/details/8236942 糖教题解处:http://blog.csdn.net/skywalkert ...

  3. Codeforces Round #536 (Div. 2) F 矩阵快速幂 + bsgs(新坑) + exgcd(新坑) + 欧拉降幂

    https://codeforces.com/contest/1106/problem/F 题意 数列公式为\(f_i=(f^{b_1}_{i-1}*f^{b_2}_{i-2}*...*f^{b_k} ...

  4. D - Power Tower欧拉降幂公式

    题意:给你一个数组a,q次查询,每次l,r,要求 \(a_{l}^{a_{l+1}}^{a_{l+2}}...{a_r}\) 题解:由欧拉降幂可知,最多log次eu(m)肯定变1,那么直接暴力即可,还 ...

  5. 2018牛客网暑期ACM多校训练营(第四场) A - Ternary String - [欧拉降幂公式][扩展欧拉定理]

    题目链接:https://www.nowcoder.com/acm/contest/142/A 题目描述 A ternary string is a sequence of digits, where ...

  6. hdu4549 矩阵快速幂 + 欧拉降幂

    R - M斐波那契数列 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit  ...

  7. Applese涂颜色-欧拉降幂公式

    链接:https://ac.nowcoder.com/acm/contest/330/E来源:牛客网 题目描述 精通程序设计的 Applese 叕写了一个游戏. 在这个游戏中,有一个 n 行 m 列的 ...

  8. TOJ 3151: H1N1's Problem(欧拉降幂)

    传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=3151 时间限制(普通/Java): ...

  9. HDU4704(SummerTrainingDay04-A 欧拉降幂公式)

    Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submi ...

随机推荐

  1. GIT版本管理工具教程

    目录 GIT版本管理工具教程 一 Git初始化 二 简单指令使用 基本操作 简单总结 三 Git进阶 Git三大区域 Git回滚 Git分支 Git工作流 四 Github代码管理仓库 第一步:注册G ...

  2. jenkins 比较好的学习的文章

    来自 :  https://www.cnblogs.com/horizonli/tag/jenkins/

  3. React组件安装使用和生命周期函数

    React安装在使用react时 需要安装 两个模块 react react-dom 初始化时 需要用到react-dom中的render方法 具体如下: import ReactDOM from & ...

  4. JPA笔记2 OneToMany

    package one_to_many; import java.util.HashSet; import java.util.Set; import javax.persistence.Cascad ...

  5. tushare库:免费的python财经数据接口

    tushare官网以及在线文档http://tushare.org/ 安装    pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tus ...

  6. Python 安装cx_Oracle模块

    1.Python安装cx_Oracle模块需要安装Oracle,并在环境变量中添加Oracle的路径. 2.没有安装Oracle的需要下载一个oci.dll的文件,并把文件的路径添加到path中. 如 ...

  7. spring-cloud-kubernetes服务发现之在k8s环境下开发spring cloud应用

    通常情况下,我们的线上的服务在迁移到k8s环境下的时候,都是采用平滑迁移的方案.服务治理与注册中心等都是采用原先的组件.比如spring cloud应用,在k8s环境下还是用原来的一套注册中心(如eu ...

  8. shell 字符菜单管理

    1.创建一个脚本func.sh 脚本如下func2.sh #!/bin/bash function menu(){ title="My Menu" url="www.la ...

  9. 201871010117-石欣钰《面向对象程序设计(java)》第十三周学习总结

    项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...

  10. echo和printf打印输出

    [root@node2 scprits]# echo Hello World! Hello World! [root@node2 scprits]# echo 'Hello World!' Hello ...