设为首页 加入收藏

TOP

HDU1061-Rightmost Digit(快速幂取模)
2015-07-20 17:47:45 来源: 作者: 【 】 浏览:1
Tags:HDU1061-Rightmost Digit 快速

题目链接


题意:求n^n的个位数的值。

思路:快速幂求值

代码:

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        using namespace std; typedef __int64 ll; //typedef long long ll; const int MOD = 1000000000; ll n; ll pow_mod(ll k) { if (k == 1) return n % MOD; ll a = pow_mod(k / 2); ll ans = a * a % MOD; if (k % 2 == 1) ans = ans * n % MOD; return ans; } int main() { int cas; scanf("%d", &cas); while (cas--) { scanf("%I64d", &n); ll ans = pow_mod(n); while (ans > 10) { ans %= 10; } printf("%I64d\n", ans); } return 0; }
      
     
    
   
  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 1442 Black Box treap求区间.. 下一篇ZOJ 3209 Dancing Links

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Python中文网 - 人生 (2025-12-24 18:49:47)
·【整整648集】这绝对 (2025-12-24 18:49:44)
·Python超详细一条龙 (2025-12-24 18:49:42)
·【超详细】JDK 下载 (2025-12-24 18:19:32)
·Java_百度百科 (2025-12-24 18:19:29)