传送门: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. Highcharts 配置语法

    Highcharts 配置语法 本章节我们将为大家介绍使用 Highcharts 生成图表的一些配置. 第一步:创建 HTML 页面 创建一个 HTML 页面,引入 jQuery 和 Highchar ...

  2. Leetcode 1021. 最佳观光组合

    1021. 最佳观光组合  显示英文描述 我的提交返回竞赛   用户通过次数91 用户尝试次数246 通过次数92 提交次数619 题目难度Medium 给定正整数数组 A,A[i] 表示第 i 个观 ...

  3. 网络编程socketserver实现并发

    import socketserver import struct import json import os class FtpServer(socketserver.BaseRequestHand ...

  4. Linux五种IO模型(同步 阻塞概念)

    Linux五种IO模型 同步和异步 这两个概念与消息的通知机制有关. 同步 所谓同步,就是在发出一个功能调用时,在没有得到结果之前,该调用就不返回.比如,调用readfrom系统调用时,必须等待IO操 ...

  5. jetty安装教程

    jetty是一个类似tomcat的应用服务器,:较tomcat少些JEE的扩展所以比tomcat还再轻量一些. 1.下载 各版本下载链接:http://central.maven.org/maven2 ...

  6. png文件格式详解,获取文件的修改时间,创作时间

    http://dev.gameres.com/Program/Visual/Other/PNGFormat.htmhttp://www.360doc.com/content/11/0428/12/10 ...

  7. 逆袭之旅DAY10.东软实训.

  8. Win10系列:UWP界面布局基础1

    随着技术的不断发展,使用者对应用程序的界面体验提出了更高的要求,为了应对越来越复杂的界面设计需求和有效的简化界面开发过程,微软公司在其应用程序的开发技术当中引入一套新的应用程序界面描述语言,这就是XA ...

  9. Win10系列:JavaScript 数据绑定

    使用数据绑定可以使页面中元素的属性值与数据源中的数据同步,其中数据源可以来自数据库.文件以及自定义的数据等.在常用的数据绑定方法中,简单对象绑定是将HTML元素与一个仅包含数据的简单对象相绑定,模板绑 ...

  10. react+dva+antd/antd-mobile

    github仓库pc: https://github.com/llcMite/react-dva-antd.git github仓库mobile:https://github.com/llcMite/ ...