hdu4059---The Boss on Mars(容斥原理+前n项的4次方和)

7 篇文章 0 订阅
5 篇文章 0 订阅

Problem Description
On Mars, there is a huge company called ACM (A huge Company on Mars), and it’s owned by a younger boss.

Due to no moons around Mars, the employees can only get the salaries per-year. There are n employees in ACM, and it’s time for them to get salaries from their boss. All employees are numbered from 1 to n. With the unknown reasons, if the employee’s work number is k, he can get k^4 Mars dollars this year. So the employees working for the ACM are very rich.

Because the number of employees is so large that the boss of ACM must distribute too much money, he wants to fire the people whose work number is co-prime with n next year. Now the boss wants to know how much he will save after the dismissal.

Input
The first line contains an integer T indicating the number of test cases. (1 ≤ T ≤ 1000) Each test case, there is only one integer n, indicating the number of employees in ACM. (1 ≤ n ≤ 10^8)

Output
For each test case, output an integer indicating the money the boss can save. Because the answer is so large, please module the answer with 1,000,000,007.

Sample Input

2
4
5

Sample Output

82
354
Hint

Case1: sum=1+3*3*3*3=82
Case2: sum=1+2*2*2*2+3*3*3*3+4*4*4*4=354

Author
ZHANG, Chao

Source
2011 Asia Dalian Regional Contest

Recommend

首先考虑n的素因子,然后统计可以用容斥
14+24+34+...+n4 可以尝试推公式
公式是:
S(n)= 6n5+15n4+10n3n30
由于要取模,所以要用下逆元

/*************************************************************************
    > File Name: hdu4059.cpp
    > Author: ALex
    > Mail: zchao1995@gmail.com 
    > Created Time: 2015年05月28日 星期四 16时49分35秒
 ************************************************************************/

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#include <set>
#include <vector>

using namespace std;

const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;

vector <int> mst;
const int mod = 1000000007;

LL calc(LL n) {
    LL ans = 0;
    LL A = 6LL;
    for (int i = 1; i <= 5; ++i) {
        A *= n;
        A %= mod;
    }
    ans += A;
    A = 15LL;
    for (int i = 1; i <= 4; ++i) {
        A *= n;
        A %= mod;
    }
    ans += A;
    A = 10LL;
    for (int i = 1; i <= 3; ++i) {
        A *= n;
        A %= mod;
    }
    ans += A;
    ans -= n;
    ans = (ans % mod + mod) % mod;
    ans *= (233333335LL % mod);
    ans %= mod;
    return ans;
}

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        LL n, m;
        scanf("%lld", &n);
        m = n;
        mst.clear();
        for (int i = 2; i * i <= n; ++i) {
            if (n % i == 0) {
                mst.push_back(i);
                while (n % i == 0) {
                    n /= i;
                }
            }
        }
        if (n > 1) {
            mst.push_back(n);
        }
        LL ans = calc(m);
        LL C = 0;
        int size = mst.size();
        for (int i = 1; i < (1 << size); ++i) {
            int bits = 0;
            int num = 1;
            for (int j = 0; j < size; ++j) {
                if (i & (1 << j)) {
                    ++bits;
                    num *= mst[j];
                }
            }
            int k = m / num;
            LL tmp = num;
            tmp *= num;
            tmp %= mod;
            tmp *= num;
            tmp %= mod;
            tmp *= num;
            tmp %= mod;
            tmp *= calc((LL)k);
            tmp %= mod;
            if (bits & 1) {
                C += tmp;
            }
            else {
                C -= tmp;
            }
            C = (C % mod + mod) % mod;
        }
        ans -= C;
        ans = (ans % mod + mod) % mod;
        printf("%lld\n", ans);
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值