Hdoj1286 find new friends [Euler's function of number theory]

Source: Internet
Author: User
New friend TimeLimit: 20001000 MS (JavaOthers) & #160; & #160; & #160; & #160; MemoryLimit: 6553632768 K (JavaOthers) TotalSubmission (s ): 7912 & #160; & #160; & #160; & #160; Accepted

Find new friends Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission (s): 7912 Accepted Submission (s): 4157

Problem Description the New Year is approaching. The Pig Association is preparing to have a party. we already know that there are N members and the number of members ranges from 1 to N. the number of the president is N, if you are an old friend of the President, the member's number must have an appointment with N greater than 1. Otherwise, they will all be new friends. now the president wants to know how many new friends there are? Compile a program to help the president calculate it.
The first line of Input is the number of test data groups CN (Case number, 1 Output outputs the number of new friends in a row for each N, so that a total of CN rows are Output.
 
Sample Input
22560824027
 
Sample Output
768016016

Template:

#include 
  
   #include 
   
    int oular(int n){int sum = 1;for(int i = 2; i*i <= n; i ++){if(n%i == 0){n /= i; sum *= (i-1);while(n%i == 0){sum *= i;n /= i;}}}if(n > 1) sum*=(n-1);return sum;}int main(){int t, n;scanf("%d", &t);while(t --){scanf("%d", &n);printf("%d\n", oular(n));}return 0;} 
   
  


Related Article

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.