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
这一套题做错了几次,按理说直接用等差数列求和公式就行了,主要是要考虑一些运算符的结核性问题: 四则运算符(+.-.*./)和求余运算符(%)结合性都是从左到右. 于是,我自己写了一个版本,主要是考虑( ...
随机推荐
- webUpload上传插件的一些bug
当你给上传按钮的父级或当前元素添加一个display:none时 你可能遇到了这样的一个问题.当你在点击显示这个按钮时 你发现按钮失效了 你需要点击F12才可以. flash 版本太低,请至少大于等于 ...
- LeetCode OJ-- Spiral Matrix
https://oj.leetcode.com/problems/spiral-matrix/ 螺旋矩阵,逆着转,输出矩阵中的元素. 在纸上模仿,然后记左上角(l1,l2)右上角(l1,r2),左下角 ...
- Anaconda3中Python3.5和Python2.7共存
开始-所有程序-Anaconda3-Anaconda Prompt conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/a ...
- 微信小程序踩坑之一[thist]使用技巧
刚上手小程序 时,习惯把this当成jquery中的$(this)来用,实际上这两个还是有差别的 在页面方法中调用其他方法,一般是用this.function(),直接调用小程序 的方法或函数则是用w ...
- facebook面试题【转】
1. 给两个类A和Bclass A {public void foo (A a) { ...}}class B extends A {public void foo (B b) { ...}}问这么写 ...
- Wireshark如何选择多行
Wireshark如何选择多行 在Wireshark中,用户经常需要选择几行,然后进行批量操作,如导出或者分析.但Wireshark没有提供通过鼠标直接选择多行的功能.这个时候,用户需要采用标记分 ...
- 会话跟踪技术Cookieless
会话跟踪技术Cookieless 在Web应用中,通常使用Cookie记录用户的状态,如用户名.访问时间等信息.当进行HTTP请求的时候,会自动发送Cookie信息给服务器.服务器接收到,就可以判 ...
- Codeforces Gym 100203H Highways 最小生成树
原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf 题解 给你平面上若干点,生成一颗完全图,让 ...
- mysql 设置默认id自增开始下标
alter table 表名 AUTO_INCREMENT 此处写你想让id从几开始增长的数字:
- windows上安装Ipython notebook
最近有一个培训机构找笔者来做一份Python的培训教材,顺带着研究了下python notebook,发现很好很强大,现把初步的安装步骤记录如下: 1.安装Python ...