Find new Friends (Euler functions)

Source: Internet
Author: User

Find new friends

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 8976 Accepted Submission (s): 4736

Transmission Door

Problem description New Year is coming, "pig head to help the association" ready to engage in a party, already know the existing member N, the member from 1 to n number, where the president's number is N, and the president is an old friend, then the member's number affirmation and N has more than 1 of the convention number, otherwise are new friends , now the president wants to know how many new friends there are? Please make up the program gang length calculation.

The first line of input is the number of groups of test data cn (case number,1<cn<10000), followed by a CN line positive integer n (1<n<32768), representing the number of members.

Output for each n, the number of new friends out of a line, so that a total of CN line output.

Sample Input22560824027

Sample Output768016016 Euler function: ******* written in detail tomorrow, not now.
1#include <iostream>2 using namespacestd;3 Const intmaxn=32790;4 inteuler[maxn+2];5 voidMake ()6 {7euler[1]=0;8      for(intI=2; i<=maxn;++i)9euler[i]=i;Ten      for(intI=2; i<=maxn;++i) One         if(euler[i]==i) A              for(intj=i;j<=maxn;j+=i) -euler[j]=euler[j]/i* (I-1); - } the intMain () - { - Make (); -     intn,t,sum; +Cin>>T; -      while(t--) +     { ACin>>N; atcout<<euler[n]<<Endl; -     } -     return 0; -}

Another way:

1#include <stdio.h>2 intgcdintXinty)3 {4     if(y==0)5         returnx;6     Else7         returnGCD (y,x%y);8 }9 intMain ()Ten { One     intN; Ascanf"%d",&N); -      while(n--) -     { the         inta[32800]={0}; -         intI,j,num; -         intflag=0; -scanf"%d",&num); +          for(i=2; i<num;i++) -         { +             if(num%i==0) A             { at                  for(j=i;j<num;j+=i) -a[j]=1; -             } -         } -         intCount=0; -          for(inti =0; i < num; ++i) in         { -             if(a[i]==0) tocount++; +         } -printf"%d\n", count-1); the     } *}

Find new Friends (Euler functions)

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.