Problem 1759 Super A^B mod CAccept: 456    Submit: 1488
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太大了10^1000000,无从下手。
a^b%c=a^(b%phi(c))%c ,注意a==c的情况
这句话,想起了 费马小定理 a^b%c=a^(b%(c-1))%c; c是互数,a,c互质的时候。
费马小定理是一个特殊的总结吧。这个是通式。
*/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std; char b[]; __int64 Euler(__int64 n)
{
__int64 i,temp=n;
for(i=;i*i<=n;i++)
{
if(n%i==)
{
while(n%i==)
n=n/i;
temp=temp/i*(i-);
}
}
if(n!=) temp=temp/n*(n-);
return temp;
} __int64 power_sum2(__int64 a,__int64 n,__int64 mod)
{
__int64 ans=;
while(n)
{
if(n&)
{
ans=(ans*a)%mod;
}
n=n>>;
a=(a*a)%mod;
}
return ans;
} int main()
{
__int64 a,c,len,k,cur,i;
while(scanf("%I64d",&a)>)
{
scanf("%s",b+);
scanf("%I64d",&c);
if(a==c)
{
printf("0\n");
continue;
}
len=strlen(b+);
k=Euler(c);
for(i=,cur=;i<=len;i++)
{
cur=cur*+b[i]-'';
cur=cur%k;
}
printf("%I64d\n",power_sum2(a%c,cur,c));
}
return ;
}

fzou 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. FZU:1759-Problem 1759 Super A^B mod C (欧拉降幂)

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

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

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

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

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

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

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

  8. K - 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 ...

  9. fzu1759 Super A^B mod C 扩展欧拉定理降幂

    扩展欧拉定理: \[ a^x \equiv a^{x\mathrm{\ mod\ }\varphi(p) + x \geq \varphi(p) ? \varphi(p) : 0}(\mathrm{\ ...

随机推荐

  1. Java几个基本概念

    To xj 编译:test.java->test.class反编译:test.class->test.java打jar包:test.class->test.jar打war包:test ...

  2. Python str转化成数字

    原地址 http://www.cnblogs.com/wuxiangli/p/6046800.html   int(x [,base ])         将x转换为一个整数     long(x [ ...

  3. 总结day13 ----内置函数

    内置函数 我们一起来看看python里的内置函数.什么是内置函数?就是Python给你提供的,拿来直接用的函数,比如print,input等等.截止到python版本3.6.2,现在python一共为 ...

  4. java日期时间

    字母 日期或时间元素 表示 示例 G Era 标志符 Text AD y 年 Year 1996; 96 M 年中的月份 Month July; Jul; 07 w 年中的周数 Number 27   ...

  5. 晦涩难懂的shell命令

    初学shell脚本,过程中发现许多不易于理解的脚本语言,网上各种查找学习之后,择优精简一番,做出以下总结,方便以后遗忘了回顾,也为像我一样的初学者提供方便——推荐给初学者的一本书:<Linux ...

  6. Linux(ubuntu18.04)切换python版本

    前言 Ubuntu18.04系统在安装python时会安装两个版本:2.7和3.6.默认情况下系统环境使用的是python2,但是我们有时需要使用python3来作为我们的开发环境,所以需要自由切换p ...

  7. Linux安装 jdk、tomcat、eclipse、mysql

    概述如果需要在Linux下进行JavaEE的开发,我们需要安装如下软件: 安装JDK 安装步骤 0) 先将软件通过xftp5 上传到/opt 下 1) 解压缩到/opt tar -zxvf  jdk. ...

  8. springboot第四篇:debug模式开发运用

    前提:项目是以maven project结构建立的,现状是无法进行断点调试的.怎么才能在eclipse里进行调试呢? 需要:①将项目打包部署到tomcat ②往项目加入dynamic web modu ...

  9. golang (4) golang 操作mongdb

    1. 数据按照时间聚合操作 1.1 正常的数据结构 { "_id" : ObjectId("5cac8d7b1202708adf5d4b64"), " ...

  10. hibernate_Session接口_load_get

    hibernate读取数据库内容,用 1,session.get(Class类型,主键); 立马发出sql语句.从数据库中取出值装到对象里去 2,session.load(Class类型,主键); 从 ...