Euler would love programming

In number theory, Euler's totient or phi function, φ ( n ) φ(n) , is an arithmetic function that counts the totatives of n n , that is, the positive integers less than or equal to n n that are relatively prime to n n .

What is the minimum value of phi function for 99 < n < 111 99<n<111 ?

Note: n n is a natural number.


The answer is 32.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

5 solutions

Kenny Lau
Aug 29, 2014

Java:

public class brilliant{
    public static void main(String args[]){
        int min=-1;
        for(int i=100;i<111;i++){
            int phi = 0;
            for(int j=1;j<i;j++){
                if(gcd(i,j)==1) phi++;
            }
            if(min==-1||phi<min) min=phi;
        }
        System.out.println(min);
    }
    private static int gcd(int i,int j){
        if(i==0) return j;
        else return gcd(Math.abs(j-i),i);
    }
}
David Holcer
Mar 28, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import fractions
def phi(n):
    amount = 0
    for k in range(1, n + 1):
        if fractions.gcd(n, k) == 1:
            amount += 1
    return amount
array=[]
for i in range(100,111):
    array.append(phi(i))
print min(array)

Modified from source .

Himanshu Arora
May 29, 2014

\( #include <iostream>

using namespace std;

int gcd(int a, int b){ int c; while(a!=0){ c=a; a=b%a; b=c; } return b;

} int phi(int d){ int p=0; for (int i=1; i<=d; i++){ if(gcd(d,i)==1){p=p+1;} } return p; }

int main() { int min=phi(100); for(int l=100; l<=110; l++) { //cout<<phi(l)<<endl; if(phi(l)<=min){min=phi(l);} } cout<<"minimum value is: "<<min; return 0; } \)

@Himanshu Arora I donot understand your solution can you clarify it?

Mardokay Mosazghi - 6 years, 10 months ago
Giorgos K.
May 24, 2018

using M a t h e m a t i c a Mathematica

Min@Table[EulerPhi@n,{n,100,110}]

returns 32 32

Edwin Gray
May 24, 2018

Let p 1, p 2, p 3,......, p n be the distinct prime factors o n Then phi(n) = n [1 - 1/(p_1)] [1 - 1/(p 2)]*...........*[1 - 1/(p n)]. Ed Gray

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...