HDU 3923 Invoker(Polya原理+费马小定理)

题目链接:
HDU 3923 Invoker
题意:
t 种颜色来涂n颗珠子的项链,问本质不同的珠子有多少个?考虑翻转和旋转。结果 mod 1000000007
分析:
模版题。需要注意最后需要除以 2n ,又因为结果 ,可以用费马小定理,相当于乘以 quick_pow(2n,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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值