4939 Euler function [one in number theory with practice]

Source: Internet
Author: User

4939 Euro-Pull function

time limit: 1 sspace limit: KBtitle level: Diamonds Diamond SolvingTitle Description Description

Enter a number n, output the number of integers less than n and N-intertextuality

Enter a description Input Description

Contains multiple sets of data, ending at n=0

The number of test data groups is not much, do not have to hit the table after output

Output description Output Description

A set of data rows

Sample input Sample Input

364684

346

5432

11

24

0

2333333

233333333

0

233333333333333

2333333333333333333333333333333333333333333333333

Sample output Sample Output

165120

172

2304

10

8

Data range and Tips Data Size & Hint

1<n<9223372036854775807

Attention to detail optimization, otherwise the nineth set of data may time out

Category labels Tags Click here to expandNo label

Step by step according to the teacher, converted into code, the results of data card memory.

40-Point Code (MLE)

#include <cstdio>#include<iostream>using namespacestd;#defineN 100001intn,a[n]={0};intMain () { while(SCANF ("%d", &n) = =1){        if(!n) Break; Doubles=N; inti,j;  for(i=2;; i++){            if(n==1) Break;  for(j=0;; J + +){                if(n%i) Break; N/=i; } A[i]=J; }        intE=i;  for(i=2; i<=e;i++){            if(!a[i])Continue; Doublet=i; S*=(1.0-1.0/t); } printf ("%d\n",(int) s);  for(intI=1; i<=e;i++) a[i]=0; }    return 0;}

Read the puzzle, optimize the code

AC Code:

#include <cstdio>#include<iostream>using namespacestd;intMain () {Long LongN,ans;  while(cin>>N) {        if(!n) Break; Ans=N; if(n%2==0){             while(n%2==0) n/=2; Ans/=2; }         for(Long LongI=3; i*i<=n;i+=2){            if(n%i==0){                 while(n%i==0) n/=i; Ans=ans/i* (I-1); }        }        if(n>1) ans=ans/n* (n1); cout<<ans<<Endl; }    return 0;}

4939 Euler function [one in number theory with practice]

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.