天天看点

hdu 4059 The Boss on Mars

The Boss on Mars

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1934    Accepted Submission(s): 580

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

题解及代码:

       这道题目的综合性还是非常强的。首先说一下题目,就是求小于n而且与n互素的数的四次方的和。

       说一下思路吧:首先我们求出1---n-1的全部的数的四次方的和,之后将n进行素因子分解。求出n的全部因子,然后减去包括这些因子的数的四次方就能够了。

       大体上的思路有了,来处理一下细节:1.首先我们要求出四次方和的公式   2.素数打表   3.求逆元(由于四次方和公式有一个分母,取余时要乘上逆元)

       4.素因子分解    5.容斥原理

       搞定这5步,我们这道题就能做了,所以说综合性很强。

详细见代码吧: