题目链接:
HDU 3923 Invoker
题意:
t
种颜色来涂
分析:
模版题。需要注意最后需要除以
2n
,又因为结果
,可以用费马小定理,相当于乘以
quick_pow(2∗n,1000000005).
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
typedef long long ll;
const ll mod = (ll)(1e9) + 7;
const int MAX_N = 10010;
ll POW[MAX_N];
int gcd(int x, int y)
{
return y == 0 ? x : gcd(y, x % y);
}
ll qucik_pow(ll x, ll y)
{
ll res = 1, tmp = x;
while(y) {
if(y & 1) res = res * tmp % mod;
tmp = tmp * tmp % mod;
y >>= 1;
}
return res;
}
int main()
{
int n, t, T, cases = 0;
scanf("%d", &T);
while(T--) {
scanf("%d%d", &t, &n);
POW[0] = 1;
for(int i = 1; i <= n; ++i) POW[i] = POW[i - 1] * t % mod;
ll a = 0, b = 0;
for(int i = 0; i < n; ++i) {
a = ( a + POW[gcd(i, n)]) % mod;
}
if(n % 2) b = n * POW[(n + 1) / 2] % mod;
else b = n / 2 * (POW[n / 2 + 1] + POW[n / 2]) % mod;
ll tmp = qucik_pow(2 * n, mod - 2);
printf("Case #%d: %lld\n", ++cases, (a + b) * tmp % mod);
}
return 0;
}