快速幂 --- CSU 1556: Jerry's trouble
来源:互联网 发布:linux写入文件命令 编辑:程序博客网 时间:2024/06/09 05:35
Jerry's troubleProblem's Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1556
View Code
Problem's Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1556
Mean:
略。
analyse:
水题,直接快速幂。
Time complexity: O(n)
Source code:
// Memory Time // 1347K 0MS // by : crazyacking // 2015-03-29-19.18 #include<map> #include<queue> #include<stack> #include<cmath> #include<cstdio> #include<vector> #include<string> #include<cstdlib> #include<cstring> #include<climits> #include<iostream> #include<algorithm> #define MAXN 1000010 #define LL long long using namespace std; const LL MOD=1e9+7; LL quick_pow(LL a,LL b,LL m) { LL ans=1; while(b) { if(b&1) { ans*=a; ans%=m; } a*=a; a%=m; b/=2; } return ans%m; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); // freopen("C:\\Users\\Devin\\Desktop\\cin.cpp","r",stdin); // freopen("C:\\Users\\Devin\\Desktop\\cout.cpp","w",stdout); LL n,m; while(cin>>n>>m) { LL sum=0; for(int i=1;i<=n;++i) { sum+=quick_pow(i,m,MOD); sum%=MOD; } cout<<sum%MOD<<endl; } return 0; } /* */ /************************************************************** Problem: 1556 User: crazyacking Language: C++ Result: Accepted Time:2704 ms Memory:1476 kb ****************************************************************/
0 0
- csu 1556: Jerry's trouble(快速幂)
- CSU - 1556 Jerry's trouble(快速幂)
- 快速幂 --- CSU 1556: Jerry's trouble
- CSU - 1556 Jerry's trouble(快速幂取模)
- CSU 1556-Jerry's trouble(快速幂)
- csu 1556: Jerry's trouble (快速幂取模)
- 湖南多校对抗赛---Jerry's trouble
- 湖南多校对抗赛3.28 J - Jerry's trouble
- CSU 1556 快速幂
- CSU 1658 IQ of XUEXX’s descendants 矩阵快速幂
- Jerry(Yahoo) 's speech
- Jerry's Tom
- codeforces626D . Jerry's Protest (概率)
- king's trouble II
- king's trouble II
- king's trouble I
- king's trouble I
- Codeforces 626D Jerry's Protest 【概率】
- JAVA
- dp --- CSU 1547: Rectangle
- Water --- CSU 1550: Simple String
- math --- CSU 1554: SG Value
- STL or 线段树 --- CSU 1555: Inversion Sequence
- 快速幂 --- CSU 1556: Jerry's trouble
- 操作系统——进程控制(二)
- 1001. 害死人不偿命的(3n+1)猜想
- STL or Force --- CSU 1553: Good subsequence
- 三分 --- CSU 1548: Design road
- 三分 --- ZOJ 3203 Light Bulb
- 三分 --- POJ 3301 Texas Trip
- 三分套三分 --- HDU 3400 Line belt
- dp --- Codeforces 245H :Queries for Number of Palindromes