- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Euler’s Totient function for all numbers smaller than or equal to n in java
Following is a program to get the result of Euler’s Totient function for all numbers smaller than or equal to n when n is given.
Program
import java.util.Scanner; public class EulerTotient { public static int gcd(int a,int b){ int i, hcf = 0; for(i = 1; i <= a || i <= b; i++) { if( a%i == 0 && b%i == 0 ) hcf = i; } return hcf; } public static void main(String args[]){ Scanner sc = new Scanner(System.in); System.out.println("Enter the n value :"); int n = sc.nextInt(); for (int i = 1; i <= n; i++){ int x = 1; for (int j = 2; j < i; j++){ if (gcd(j, n) == 1){ x++; } } System.out.println(x); } } }
Output
Enter the n value 10 1 1 1 2 2 2 2 3 3 4
- Related Articles
- Print all Jumping Numbers smaller than or equal to a given value in C++
- Count numbers (smaller than or equal to N) with given digit sum in C++
- Find all factorial numbers less than or equal to n in C++
- Print all prime numbers less than or equal to N in C++
- Minimum numbers which is smaller than or equal to N and with sum S in C++
- Print all Semi-Prime Numbers less than or equal to N in C++
- An interesting solution to get all prime numbers smaller than n?
- Largest number smaller than or equal to N divisible by K in C++
- Cube Free Numbers smaller than n
- Count of Binary Digit numbers smaller than N in C++
- Find maximum product of digits among numbers less than or equal to N in C++
- Count elements smaller than or equal to x in a sorted matrix in C++
- How to find numbers in an array that are greater than, less than, or equal to a value in java?
- Euler’s criterion in java
- First element greater than or equal to X in prefix sum of N numbers using Binary Lifting in C++

Advertisements