传送门:http://acm.fzu.edu.cn/problem.php?pid=1759

Accept: 1161    Submit: 3892
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
 
 
题意:
给出a,b,c,求a的b次方对c取模的结果
 
思路:
题意好理解,但是主要是a,b,c的范围比较大,所以这里面需要一个降幂公式:
 
 #include<stdio.h>
#include<string.h>
typedef long long LL; const int MAXX = 1e6;
LL c,d;
char b[MAXX+]; LL quick_pow(LL a, LL b, LL mod) {
LL ans = ;
while(b > ) {
if(b&) {
b--;
ans = ans *a %mod;
}
b>>=;
a=a*a%mod;
}
return ans;
} LL Euler (LL n) {
LL rea=n;
for(int i=; i*i<=n; i++)
if(n%i==)
{
rea=rea-rea/i;
do
n/=i;
while(n%i==);
}
if(n>)
rea=rea-rea/n;
return rea;
}
LL jieguo(LL a,char b[],LL c,LL mod) {
LL sum = ;
sum = (b[] - '') % mod;
LL len = strlen(b);
for(int i = ;i<len;i++) {
sum*=;
sum=(sum+b[i]-'')%mod;
}
return quick_pow(a,sum+mod,c);
}
int main() { while(scanf("%lld%s%lld", &c, b, &d)!=EOF){
LL ola=Euler(d);
printf("%lld\n",jieguo(c,b,d,ola));
}
return ;
}

FZU 1759-Super A^B mod C的更多相关文章

  1. FZU 1759 Super A^B mod C 指数循环节

    Problem 1759 Super A^B mod C Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description G ...

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

  3. fzou 1759 Super A^B mod C

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

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

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

  5. FZU Super A^B mod C(欧拉函数降幂)

    Problem 1759 Super A^B mod C Accept: 878    Submit: 2870 Time Limit: 1000 mSec    Memory Limit : 327 ...

  6. FZU 1759 题解 欧拉降幂

    本题考点:欧拉降幂 Super A^B mod C Given A,B,C, You should quickly calculate the result of A^B mod C. (1<= ...

  7. Day7 - B - Super A^B mod C FZU - 1759

    Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B ...

  8. Super A^B mod C (快速幂+欧拉函数+欧拉定理)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759 题目:Problem Description Given A,B,C, You should quick ...

  9. FZU 1759 欧拉函数 降幂公式

    Description   Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000 ...

  10. FZU 2212 Super Mobile Charger(超级充电宝)

    [Description] [题目描述] While HIT ACM Group finished their contest in Shanghai and is heading back Harb ...

随机推荐

  1. hdu-4180-exgcd

    RealPhobia Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. 洛谷P1075 质因数分解

    题目描述 已知正整数n是两个不同的质数的乘积,试求出两者中较大的那个质数. 输入输出格式 输入格式: 一个正整数n. 输出格式: 一个正整数p,即较大的那个质数. 输入输出样例 输入样例#1: 复制 ...

  3. 一个典型的多表参与连接的复杂SQL调优(SQL TUNING)引发的思考

    今天在看崔华老师所著SQL优化一书时,看到他解决SQL性能问题的一个案例,崔华老师成功定位问题并进行了解决.这里,在崔华老师分析定位的基础上,做进一步分析和推理,以便大家一起研究探讨,下面简述该案例场 ...

  4. snort安装使用教程(CentOS6.5)

    官网:https://www.snort.org/ 官方文档:https://www.snort.org/documents 2.安装 2.1安装依赖 yum install flex bison - ...

  5. URL to load resources from the classpath in Java

    In Java, you can load all kinds of resources using the same API but with different URL protocols: fi ...

  6. VLC添加水印

    Name: LibVLC control APIDescription: VLC media player external control libraryVersion: 2.1.3 参照:http ...

  7. 巧用call,appl有 根据对象某一属性求最大值

    查找对象数组中某属性的最大最小值的快捷方法 例如要查找array数组中对象的value属性的最大值 var array=[ { "index_id": 119, "are ...

  8. memory prefix pre,pro,penta,pseudo out _p 1

    1● pre 前的,预先   2● pro 在前,很多,赞同       3● penta 5,五     4● pseaudo   伪,假 pseudo  

  9. DMA-总结

    概念DMA “Direct Memory Access(存储器直接访问).这是指一种高速的数据传输操作,允许在外部设备和存储器之间直接读写数据.整个数据传输操作在一个称为"DMA控制器&qu ...

  10. mysql不会使用索引,导致全表扫描情况

    不会使用索引,导致全表扫描情况 1.不要使用in操作符,这样数据库会进行全表扫描,推荐方案:在业务密集的SQL当中尽量不采用IN操作符 2.not in 使用not in也不会走索引推荐方案:用not ...