HDOJ 4704 Sum 规律 欧拉定理
规律 欧拉定理:
找规律 2^n-1 ,n 非常大用欧拉定理
Sum
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1465 Accepted Submission(s): 622
2
2Hint1. For N = 2, S(1) = S(2) = 1. 2. The input file consists of multiple test cases.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std; typedef long long int LL; const LL mod=1e9+7;
const LL phi=1e9+6; char str[200000]; LL quickpow(LL x)
{
if(x==0LL) return 1LL;
LL e=2,ret=1;
while(x)
{
if(x%2)
ret=(ret*e)%mod;
e=(e*e)%mod;
x/=2LL;
}
return ret;
} int main()
{
while(scanf("%s",str)!=EOF)
{
int len=strlen(str);
/// N - 1
if(str[len-1]>'0')
{
str[len-1]--;
}
else
{
int p=len-1;
while(str[p]=='0')
{
str[p]='9';
p--;
}
str[p]--;
}
LL ret=0;
for(int i=0;i<len;i++)
{
ret=ret*10LL+str[i]-'0';
while(ret>=phi)
ret-=phi;
}
cout<<quickpow(ret)<<endl;
}
return 0;
}
HDOJ 4704 Sum 规律 欧拉定理的更多相关文章
- 题解报告:hdu 4704 Sum(扩展欧拉定理)
Problem Description Sample Input 2 Sample Output 2 Hint 1. For N = 2, S(1) = S(2) = 1. 2. The input ...
- 【HDOJ】4704 Sum
数学题.f(n) = 2^(n-1) mod (1e9+7). #include <cstdio> #define MAXN 100005 char buf[MAXN]; __int64 ...
- 数论 --- 费马小定理 + 快速幂 HDU 4704 Sum
Sum Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=4704 Mean: 给定一个大整数N,求1到N中每个数的因式分解个数的 ...
- HDU 4704 Sum (高精度+快速幂+费马小定理+二项式定理)
Sum Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%I64d & %I64u Submit Status ...
- HDU 4704 Sum(隔板原理+组合数求和公式+费马小定理+快速幂)
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=4704 Problem Description Sample Input 2 Sample Outp ...
- HDU - 4704 sum 大数取余+欧拉降幂
Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submi ...
- hdu 4704 Sum (整数和分解+快速幂+费马小定理降幂)
题意: 给n(1<n<),求(s1+s2+s3+...+sn)mod(1e9+7).其中si表示n由i个数相加而成的种数,如n=4,则s1=1,s2=3. ...
- hdoj - 1258 Sum It Up && hdoj - 1016 Prime Ring Problem (简单dfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1258 关键点就是一次递归里面一样的数字只能选一次. #include <cstdio> #inclu ...
- HDOJ(1001) Sum Problem
这一套题做错了几次,按理说直接用等差数列求和公式就行了,主要是要考虑一些运算符的结核性问题: 四则运算符(+.-.*./)和求余运算符(%)结合性都是从左到右. 于是,我自己写了一个版本,主要是考虑( ...
随机推荐
- Python入门--17--pickle
pickle模块,实际用途也很简单.单一,主要用于保存列表(list),元祖(Tuple),字典(dictionary) 当然,一定是大的列表.字典什么的,成千上万行的字典.列表,才能凸显出它的用武之 ...
- iphoneXR的tabbar底部图片的适配
在自定义tabbar的背景图时,发现在ihonexr上有点问题,主要是因为iphoneXr用的是二倍图,但是Xr的tabbar底部高度多了34像素,所以就出现了如下的情况: 解决这个问题,还比较简单, ...
- react 生命周期详解
state有时候很不听话,在某些时候,我不想他渲染,偏偏react非常智能的帮我们重复渲染. 比如最常见的就是传递的对象为空,组件依旧渲染了一次或者多次. 更多场景不举例了,对症下药. shouldC ...
- Codeforces 629 A. Far Relative’s Birthday Cake
A. Far Relative’s Birthday Cake time limit per test 1 second memory limit per test 256 megabytes ...
- 预防SQL注入笔记
SQL注入如何预防? 本文参考自owasp,重点是提供清晰,简单,可操作的指导,以防止应用程序中的SQL注入漏洞.不幸的是,SQL注入攻击很常见,这是由于两个因素: SQL注入漏洞的显着流行 目标的吸 ...
- 安装Vmware增强工具
主机: Win7 虚拟机: VMware8.0+Debian6 目标: 离线安装软件包和VMware Tools 在虚拟机上安装完debian6后 1.在vmware的菜单中选择Vm->inst ...
- VC 读取服务器上的文件(HTTP方式) [转]
CString GetStringFromUrl(LPCTSTR pszUrl){ CString str ; HINTERNET hSession = ::InternetOpen( _ ...
- 转: 写给想成为前端工程师的同学们 (from 360前端团队)
转自: http://www.75team.com/post/to-be-a-good-frontend-engineer.html 前端工程师是做什么的? 前端工程师是互联网时代软件产品研发 ...
- spoj 1811 LCS - Longest Common Substring (后缀自己主动机)
spoj 1811 LCS - Longest Common Substring 题意: 给出两个串S, T, 求最长公共子串. 限制: |S|, |T| <= 1e5 思路: dp O(n^2 ...
- 实战c++中的string系列--十六进制的字符串转为十六进制的整型(一般是颜色代码使用)
非常久没有写关于string的博客了.由于写的差点儿相同了.可是近期又与string打交道,于是荷尔蒙上脑,小蝌蚪躁动. 在程序中,假设用到了颜色代码,一般都是十六进制的,即hex. 可是server ...