(打表或数学)HDU 6063 RXD and math
2017-08-02 00:12
330 查看
HDU-2017 多校训练赛3-1008-RXD and math
题目网址: HDU 6063 RXD and math
后来.. 上苍告诉我, 标准的公式, 何不打个表看看规律!!?
然后发现本题只是求 n^k次方, 快速幂即可解决
打表过程在代码中
BTW: Bestcoder的题解附上(虽然我没看懂…)
![](https://img-blog.csdn.net/20170802001127255?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvVm9uU2RpdGU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
题目网址: HDU 6063 RXD and math
题意分析:
初看到莫比乌斯函数..觉得和莫比乌斯函数..杜教筛有关..然后推不出来后来.. 上苍告诉我, 标准的公式, 何不打个表看看规律!!?
然后发现本题只是求 n^k次方, 快速幂即可解决
打表过程在代码中
BTW: Bestcoder的题解附上(虽然我没看懂…)
代码:
#include <iostream> #include <cmath> using namespace std; #define ll long long const ll mod = 1e9+7; void seeTable(); // 打表找规律 ll quickpower(ll n, ll k) { ll ans = 1; n %= mod; while (k) { if(k & 1) ans = (ans * n) % mod; k >>= 1; n = (n*n) % mod; } return ans; } int main(int argc, char const *argv[]) { // seeTable(); // 打表可知, 其实求的就是n^k ll n, k; int cnt = 1; while (~scanf("%I64d %I64d", &n, &k)) { printf("Case #%d: ", cnt++); printf("%I64d\n", quickpower(n, k)); } return 0; } void seeTable() { for(int n = 2; n < 6; ++n) { int k = 1; while (k < 11) { int nk = pow(n, k); int sum = 0; for (int i = 1; i <= nk; ++i) { int tmp = i; bool flag = true; for (int i = 2; tmp != 1; ++i) { int cnt = 0; // 记录有多少个相同的素数 while (tmp % i == 0) { ++cnt; if(cnt > 1) { flag = false; } tmp /= i; } } if(flag) { // 每个素数只出现一次 sum += (int)sqrt((double)nk/(double)i); } } printf("n=%-3d k=%-3d \t n^k=%-8d \t result=%d\n", n, k, nk, sum); printf("==============================================================\n"); k++; } } }
相关文章推荐
- HDU 6063 RXD and math【快速幂】【打表找规律】
- 多校3 HDU - 6063 RXD and math 数学
- HDU 6063 RXD and math (打表)
- HDU 6063 RXD and math【数学】
- HDU 6063 17多校3 RXD and math(暴力打表题)
- HDU 6063 RXD and math 打表找规律 快速幂
- HDU--6063--RXD and math
- HDU 6063 RXD and math(快速幂)
- HDU 6063 RXD and math(数论)
- (2017多校训练第三场)HDU - 6063 RXD and math 找规律 + 快速幂
- HDU 6063 RXD and math
- hdu--6063 RXD and math
- HDU 6063-RXD and math
- RXD and math(HDU 6063 快速幂)
- HDU 6063 RXD and math+(快速幂)+多校联赛第三场
- Hdu 6063 - RXD and math(思维)
- HDU 6063 RXD and math
- hdu 6063 RXD and math (规律题)
- 17 多校 3 - 1008 - RXD and math(HDU 6063)
- 17暑假多校联赛3.8 HDU 6063 RXD and math