HDU 3501 Calculation 2 (Extended Euler's function)

Source: Internet
Author: User
Calculation 2

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 1264 Accepted Submission (s): 530

Problem DescriptionGiven a positive integer N, your task is to calculate the sum of the positive integers less than N which are not coprime to N. A is said to be coprime to B if A, B share no common positive divisors limit T 1.

 

InputFor each test case, there is a line containing a positive integer N (1 ≤ N ≤ 1000000000). A line containing a single 0 follows the last test case.

 

OutputFor each test case, you shocould print the sum module 1000000007 in a line.

 

Sample Input3 4 0

 

Sample Output0 2

 

AuthorGTmac

 

Source2010 ACM-ICPC Multi-University Training Contest (7) -- Host by HIT

 

Recommendzhouzeyong is actually a promotion of Euler's function. If the number is less than or equal to n, the number of the numbers of the n-grams is phi (n). the Euler's function is less than or equal to n. The sum of the numbers of the n-grams is phi (n) * n/2; so sum loss is the answer.
/* Extension of the Euler's formula for finding numbers less than N and N that do not intersect with n in HDU 3501: In a number less than or equal to n, the sum of the numbers that do not intersect with N is PHI (x) * x/2. (N> 1) */# include <stdio. h> # include <iostream> # include <string. h ># include <algorithm> using namespace std; const int MOD = 1000000007; // evaluate the Euler function long eular (long n) {long ret = n; long I; for (I = 2; I * I <= n; I ++) {if (n % I = 0) {ret-= ret/I; while (n % I = 0) n/= I; if (n = 1) break;} if (n> 1) ret-= ret/n; return ret;} int main () {long n; while (scanf ("% I64d", & n), n) {long ans = (n * (n-1) /2% MOD-eular (n) * n/2% MOD + MOD) % MOD; printf ("% I64d \ n", ans);} return 0 ;}

 

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.