HDU 4059 the boss on Mars

Source: Internet
Author: User

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 descriptionon 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.
 
Inputthe 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)
 
Outputfor 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
245
 
Sample output
82354HintCase1: sum=1+3*3*3*3=82Case2: sum=1+2*2*2*2+3*3*3*3+4*4*4*4=354 
 
Authorzhang, Chao
Source2011 Asia Dalian Regional Contest

Question and code:

This question is still comprehensive. First, let's talk about the question, that is, the sum of the four power numbers less than N and with N.

Let's talk about the idea: first, we can find the four-power sum of all numbers of 1 --- n-1, then we can break down n to all the factors of N, then, subtract the four power of the number containing these factors.

The general idea is to deal with the details: 1. first, we need to produce the formula of the four operators and two. base number table 3. reverse element (because there is a denominator for the four parties and the formula, the remainder must be multiplied by the reverse element)

4. prime factor decomposition 5. Exclusion Principle

After completing these five steps, we can do this question, so it is comprehensive.

For details, see the code:

# Include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <algorithm> using namespace STD; const long mod = 1000000007, q = 233333335; // P is the inverse element, and bool prime [10010] is obtained using the Fermat theorem; int P [1400]; int K = 0; // formula for solving four vertices and long CAL (long n) {If (n = 0) return 0; Return (N * (n + 1) % mod * (2 * n + 1) % mod * (3 * n + 3 * N-1) % mod * q % mod) % MOD ;} // rejection principle void DFS (INT base, int num_p, long N, long M, long nt, long Mu, long & sum, long long tab_p []) {If (NT = m) {long B = N/mu; If (M % 2 = 0) {sum = (Sum-mu * mu % mod * CAL (B) % mod + mod) % MOD ;} else {sum = (sum + Mu * mu % mod * CAL (B) % mod) % MOD;} return ;} for (long I = base; I <num_p; I ++) {DFS (I + 1, num_p, n, m, NT + 1, Mu * tab_p [I], sum, tab_p) ;}}// the void isprime () {long I, j; memset (Prime, true, sizeof (PRIME )); prime [0] = prime [1] = false; for (I = 2; I <10010; I ++) {If (prime [I]) {P [k ++] = I; for (j = I * I; j <10010; j + = I) prime [J] = false ;}}} int main () {isprime (); long N, ANS, tab_p [1400]; int CAS; scanf ("% d", & CAS); While (CAS --) {scanf ("% i64d", & N); n = n-1; ans = CAL (n); long M = N, t = n + 1; int num_p = 0; for (INT I = 0; I <K & P [I] * P [I] <= T; I ++) // prime factor decomposition if (T % P [I] = 0) {tab_p [num_p ++] = P [I]; while (T % P [I] = 0) {T/= P [I] ;}} if (T> 1) tab_p [num_p ++] = T; /* // output test for (INT I = 0; I <num_p; I ++) {printf ("% d", tab_p [I]);} puts (""); // test end */long sum = 0; For (INT I = 0; I <num_p; I ++) // subtract the non-prime part from {n = m/tab_p [I]; sum = (sum + tab_p [I] * tab_p [I] % mod * tab_p [I] % mod * tab_p [I] % mod * CAL (N) % MOD ;} for (long I = 2; I <= num_p; I ++) // solves DFS (0, num_p, M, I, 0ll, 1ll, sum, tab_p); printf ("% i64d \ n", (ANS-sum + mod) % mod);} return 0 ;}






HDU 4059 the boss on Mars

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.