hdu 1061 数论
来源:互联网 发布:马穆鲁克王朝知乎 编辑:程序博客网 时间:2024/06/06 04:37
由于n比较大,可以用到二分优化,我在算法的书上看到过,后来很多oj都有这样的水题了,只能说数论这东东,看过了就都是水题,没看过真心难想
代码如下:
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>using namespace std;int modexp(int a,long long b,int n)//a^b%n,就是这个,可以看到是用的二分优化滴{ int t=1; a %=n; while(b>0) { if(b%2==1) t =(t*a)%n; a=(a*a)%n; b /=2; } return t;}int main(){ //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); long long n; int ans,i,ncase; cin>>ncase; while(ncase--) { cin>>n; ans=n%10; ans=modexp(ans,n,10); cout<<ans<<endl; } return 0;}
- hdu 1061 数论
- HDU 1061 Rightmost Digit 数论
- HDU 2204 (数论)
- 数论 MillerRabin hdu 3792
- HDU 3123 数论
- 【数论】HDU-4196-Remoteland
- HDU 3988 数论
- HDU 1787 数论
- hdu 1395 数论
- HDU 2104数论 欧几里得
- HDU 1060 数论
- HDU 2161 Primes 数论
- HDU 1695 GCD 数论
- HDU 1568 Fibonacci 数论
- hdu 4542 数论
- hdu 1722(数论)
- hdu 1492(数论)
- hdu 2554 (数论)
- 揭秘TI移动AP中ARM核的应用演变
- Python读取文件,检测文件编码及去除UTF8 BOM
- Web load Spring
- HDU 3634 City Planning
- 原码、反码、补码、float、ASCII码
- hdu 1061 数论
- java异常及其处理
- ProxyPassReverse
- 内存数据库
- 登录例子实践---三层架构
- sz rz 的安装
- 城府的修练
- android基本界面控件
- CareerCup-3.4