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<=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非常大,只能用字符串处理;
需要一个降幂公式
然后带入欧拉公式,快速幂,快速乘法就可以了
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define pb push_back
#define mm(a,b) memset((a),(b),sizeof(a))
#include<vector>
typedef __int64 ll;
typedef long double ld;
//const ll mod=1e9+7;
using namespace std;
const double pi=acos(-1.0);
vector<int>v;
char x[1000005];
ll multi(ll a,ll b,ll c)//快速乘
{
ll ans=0;
while(b)
{
if(b&1)
ans=(ans+a)%c;
a=(a+a)%c;
b>>=1;
}
return ans;
}
ll pow(ll a,ll b,ll c)//快速幂
{
ll ans=1,bas=a;
while(b)
{
if(b&1)
ans=multi(ans,bas,c);
bas=multi(bas,bas,c);
b>>=1;
}
return ans;
}
ll p[1000100];
ll ola(ll n){ //欧拉函数
ll i, j, r, aa;
r = n;
aa = n;
mm(p,0);
for(i=2; i<=sqrt(n); i++)
{
if(aa%i==0)
{
r = r/i*(i-1);
while(aa%i==0)
aa /= i;
}
}
if(aa>1)
r = r/aa*(aa-1);
return r;
}
int main()
{
ll a,b,mod;
while(~sf("%I64d %s %I64d",&a,&x,&mod))
{
ll cas=ola(mod);
ll ans=0;
int num=strlen(x);
for(int i=0;i<num;i++)//求那个b%phi(c)
{
ans=ans*10+x[i]-48;
ans%=cas;
}
if(ans<0) ans+=mod;
pf("%I64d\n",pow(a,ans+cas,mod));
}
}
K - Super A^B mod C的更多相关文章
- fzou 1759 Super A^B mod C
Problem 1759 Super A^B mod CAccept: 456 Submit: 1488Time Limit: 1000 mSec Memory Limit : 32768 ...
- 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 ...
- 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 ...
- FZU Super A^B mod C(欧拉函数降幂)
Problem 1759 Super A^B mod C Accept: 878 Submit: 2870 Time Limit: 1000 mSec Memory Limit : 327 ...
- 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 ...
- Super A^B mod C (快速幂+欧拉函数+欧拉定理)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759 题目:Problem Description Given A,B,C, You should quick ...
- FZU:1759-Problem 1759 Super A^B mod C (欧拉降幂)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759 欧拉降幂是用来干啥的?例如一个问题AB mod c,当B特别大的时候int或者longlong装不下的时 ...
- fzu1759 Super A^B mod C 扩展欧拉定理降幂
扩展欧拉定理: \[ a^x \equiv a^{x\mathrm{\ mod\ }\varphi(p) + x \geq \varphi(p) ? \varphi(p) : 0}(\mathrm{\ ...
- 欧拉降幂公式 Super A^B mod C
Description Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=100000 ...
随机推荐
- Linux下RocketMQ环境的配置
RocketMQ是一款分布式消息系统,最初是由阿里巴巴消息中间件团队研发并大规模应用于生产系统,满足线上海量堆积的需求,在去年捐赠给Apache开源基金会,并列为孵化项目,今年成功的正式成为了apac ...
- 手把手教你用CAB发布OCX的简单办法
CAB是一种文件压缩格式,把OCX文件(ActiveX插件)压缩成CAB文件是为了发布它,这种发布方式给人感觉“浏览器会自动安装该插件”,很多朋友钟情于此.目前流行很多压缩工具,但WINRAR这类工具 ...
- Spring MVC报异常:org.springframework.web.util.NestedServletException: Request processing failed
在使用SpringMVC绑定基本类型(如String,Integer等)参数时,应通过@RequestParam注解指定具体的参数名称,否则,当源代码在非debug模式下编译后,运行时会引发Handl ...
- Win10更新搜狗输入法后重启输入密码蓝屏
解决办法:如果能进入安全模式,卸载搜狗输入法:不行的话(好像不行)只能重装系统:因为蓝屏后就基本开不了了!!!生气!! win10 1809 19.3月累积更新之后蓝屏:安装了搜狗输入法的win10 ...
- Open-Source performance testing tools(From other site)
http://www.appdynamics.com/blog/php/tools-of-the-trade-for-performance-and-load-testing/
- 安装 scws出现 autoconf 需要先安装
安装在终端操作, curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-latest.tar.gz tar xzf autoconf-latest.t ...
- Main.storyboard: WKWebView before iOS 11.0 (NSCoding support was broken in previous versions)
在工程里用 故事板写了 wkwebview 如果运行在 ios11以下 就会报这个错误,如果要支持iOS 11 以下的用户,请重写View部分,使用代码调用WKWebView,而不用使用故事版来加 ...
- 9.12 翻译系列:数据注解特性之ConcurrencyCheck【EF 6 Code-First系列】
原文链接:https://www.entityframeworktutorial.net/code-first/concurrencycheck-dataannotations-attribute-i ...
- java解惑--摘要
(1)下面是一个试图解决上述问题的程序,它会打印出什么呢?public class Change{public static void main(String args[]){System.out.p ...
- PHP Backdoor + Reverse Shell on Vulnerable Website
翻译总结自: https://shellgam3.com/2016/07/27/php-backdoor-reverse-shell-on-vulnerable-website/ 扫描Web服务器,爆 ...
