HDU4704:Sum(欧拉降幂公式)
2024-09-24 22:22:11
Input
2
Output
2
Sample Input
2
由公式,ans=2^(N-1)%Mod=2^((N-1)%(Mod-1)+(Mod-1)) %Mod。
注意:降幂的之后再加一个Mod-1保险,避免为负,比如此题出入1000000006时,就出问题了。
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
const int Mod=1e9+;
char c[];
ll ans,sum,g;
ll qpow(ll a,ll x){
ll res=;
while(x){
if(x&) res=res*a%Mod;
x>>=;
a=a*a%Mod;
}
return res;
}
int main()
{
int L,i,j;
while(~scanf("%s",c+)){
L=strlen(c+);
sum=;g=;
for(i=L;i>=;i--){
sum=(sum+(c[i]-'')*g)%(Mod-);
g=g*%(Mod-);
}
ans=qpow(,sum+Mod-);
printf("%lld\n",ans);
}
return ;
}
最新文章
- Shell入门教程:流程控制(6)while 循环
- [NOIP2015] 提高组 洛谷P2678 跳石头
- 通过setDB2Client*来方便的使用TRACE调优jdbc程序
- 冲刺阶段 day2
- MySQL Server 5.7解压版缺少文件无法启动
- poj 3278 Catch That Cow (广搜,简单)
- RDD.scala(源码)
- HDU 5416 CRB and Tree
- Nodejs in Visual Studio Code 11.前端工程优化
- java 获取特定天数的时间戳
- [Swust OJ 1139]--Coin-row problem
- 换行符以及for循环的优化
- ExtJS的4.1新特性简要介绍
- 关于WebService、WebApi的跨域问题
- CVE-2017-8464复现 (远程快捷方式漏洞)
- 接口测试工具-tamper data
- go标准库的学习-net/url
- Http请求帮助类
- XP、Windows7下自动关机vbs脚本,使用windows计划任务+vbs脚本在XP、Windows7下实现定时自动关机
- Python __str__函数