HDU1061-Rightmost Digit(高速功率模)
生活随笔
收集整理的這篇文章主要介紹了
HDU1061-Rightmost Digit(高速功率模)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
主題鏈接
題意:求n^n的個位數(shù)的值。
思路:高速冪求值
代碼:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm>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; }版權聲明:本文博客原創(chuàng)文章,博客,未經(jīng)同意,不得轉載。
轉載于:https://www.cnblogs.com/blfshiye/p/4722353.html
總結
以上是生活随笔為你收集整理的HDU1061-Rightmost Digit(高速功率模)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL Serve里你总要去改变的3个配
- 下一篇: 怎么应对泰山上突发的恶劣天气?