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

Hint

 

Source

FZU 2009 Summer Training IV--Number Theory
 
题意:A^B mod C
题解:

降幂公式 phi() 为欧拉函数

 #include<iostream>
#include<cstring>
#include<cstdio>
#define ll __int64
#define mod 10000000007
using namespace std;
char a[];
ll x,z;
ll quickpow(ll x,ll y,ll z)
{
ll ans=;
while(y)
{
if(y&)
ans=ans*x%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;
}
int main()
{
while(scanf("%I64d %s %I64d",&x,a,&z)!=EOF)
{
ll len=strlen(a);
ll p=phi(z);
ll ans=;
for(ll i=;i<len;i++)
ans=(ans*+a[i]-'')%p;
ans+=p;
printf("%I64d\n",quickpow(x,ans,z));
}
return ;
}

FZU 1759 欧拉函数 降幂公式的更多相关文章

  1. HDU 3221 矩阵快速幂+欧拉函数+降幂公式降幂

    装载自:http://www.cnblogs.com/183zyz/archive/2012/05/11/2495401.html 题目让求一个函数调用了多少次.公式比较好推.f[n] = f[n-1 ...

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

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

  3. UVa 10837 (欧拉函数 搜索) A Research Problem

    发现自己搜索真的很弱,也许做题太少了吧.代码大部分是参考别人的,=_=|| 题意: 给出一个phi(n),求最小的n 分析: 回顾一下欧拉函数的公式:,注意这里的Pi是互不相同的素数,所以后面搜索的时 ...

  4. UVa 11440 (欧拉函数) Help Tomisu

    题意: 给出N和M,统计区间x ∈ [2, N!],x满足所有素因子都大于M的x的个数. 分析: 首先将问题转化一下,所有素因子都大于M 等价于 这个数与M!互素 对于k大于M!,k与M!互素等价于 ...

  5. hdu 2824 The Euler function(欧拉函数)

    题目链接:hdu 2824 The Euler function 题意: 让你求一段区间的欧拉函数值. 题解: 直接上板子. 推导过程: 定义:对于正整数n,φ(n)是小于或等于n的正整数中,与n互质 ...

  6. poj 2480 Longge's problem [ 欧拉函数 ]

    传送门 Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7327   Accepted: 2 ...

  7. (转载)O(N)的素数筛选法和欧拉函数

    转自:http://blog.csdn.net/dream_you_to_life/article/details/43883367 作者:Sky丶Memory 1.一个数是否为质数的判定. 质数,只 ...

  8. 【SPOJ-GCDEX】GCD Extreme(欧拉函数)

    题目: SPOJ-GCDEX (洛谷 Remote Judge) 分析: 求: \[\sum_{i=1}^{n}\sum_{j=i+1}^{n}gcd(i,j)\] 这道题给同届新生讲过,由于种种原因 ...

  9. (hdu step 7.2.1)The Euler function(欧拉函数模板题——求phi[a]到phi[b]的和)

    题目: The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...

随机推荐

  1. 【转】javascript打印设置

    页面中的代码:<OBJECT id="WebBrowser1" height="0" width="0"        classid ...

  2. codeforces 727F. Polycarp's problems

    题目链接:http://codeforces.com/contest/727/problem/F 题目大意:有n个问题,每个问题有一个价值ai,一开始的心情值为q,每当读到一个问题时,心情值将会加上该 ...

  3. nginx 模块讲解

    1. 通用配置选项: --prefix=<path>          指定Nginx的安装路径,所有其他的路径都要依赖于该选项 --sbin-path=<path>     ...

  4. C学习

    \a:警报 1.exit(),提前结束程序.include <stdlib.h> 2.getch()无缓存.getchar()有缓存,多条连用时注意末尾换行符否则始终.putchar(). ...

  5. auto_ptr源码剖析

    /* * Copyright (c) 1997-1999 * Silicon Graphics Computer Systems, Inc. * * Permission to use, copy, ...

  6. Apache Flume 1.7.0 发布,日志服务器

    Apache Flume 1.7.0 发布了,Flume 是一个分布式.可靠和高可用的服务,用于收集.聚合以及移动大量日志数据,使用一个简单灵活的架构,就流数据模型.这是一个可靠.容错的服务. 本次更 ...

  7. Multivariance Linear Regression练习

    %% 方法一:梯度下降法 x = load('E:\workstation\data\ex3x.dat'); y = load('E:\workstation\data\ex3y.dat'); x = ...

  8. offse

    关于offset共有5个东西需要弄清楚: 1.offsetParent 2.offsetTop 3.offsetLeft 4.offsetWidth 5.offsetHeight (1)offsetW ...

  9. String类常用方法小节

    (1)String.equals() 返回值是boolean类型 equals(Object anObject)           将此字符串与指定的对象比较. (2)length() 返回值是in ...

  10. LED BIN code

    在LED选型时,一开始我们都知道要选个某种颜色,在选个尺寸,但在到具体选的时候,就会被那些个各种各样的参数搞得迷糊,这个主要对一个最让人困惑的参数-BIN CODE做整理. BIN就是bining的缩 ...