HDU3501 Calculation 2 (Euler function)

Source: Internet
Author: User

Calculation 2Time limit:1000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i64 U SubmitStatus

Description

Given a positive integer n, your task is to calculate the sum of the positive integers less than N which was not coprime t o N. A is said to being coprime to B if A, B share no common positive divisors except 1.

Input

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

Output

For each test case, you should print the sum of module 1000000007 in a line.

Sample Input

340

Sample Output

02 Simple translation:Enter an n, which is less than N and does not match the number of n coprime with the value of modulo 1000000007. Problem Solving Ideas:Euler function, the sum of the number of less than N and n coprime is calculated, and the sum of the number minus coprime is obtained, and the sum of the number is not coprime. Code:
1#include <cstdio>2#include <cstring>3#include <iostream>4 using namespacestd;5 Const intMod=1000000007;6 intMain ()7 {8     intN;9      while(SCANF ("%d", &n)!=eof&&N)Ten     { One         Long LongTemp=n,eular=1; A         Long LongAns= (temp* (temp+1)/2)%MoD; -          for(intI=2; i*i<=temp;i++) -             if(temp%i==0) the             { -Temp/=i; -eular*=i-1; -                  while(temp%i==0) +                 { -Temp/=i; +eular*=i; A                 } at             } -         if(temp>1) eular*=temp-1; -eular%=MoD; -temp=N; -         Long LongW= (eular*temp/2)%MoD; -ans-=W; inans-=N; -          while(ans<0) ans+=MoD; toprintf"%lld\n", ans); +     } -     return 0; the}
Calculation 2

HDU3501 calculation 2 (Euler function)

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.