-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCo-Prime.java
More file actions
32 lines (28 loc) · 732 Bytes
/
Co-Prime.java
File metadata and controls
32 lines (28 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package technicals;
import java.util.*;
public class CO_PRIME {
//Co-Prime numbers are the number which have HCF 1 between them like 3 and 4 their HCF is 1, So they are Co-Prime pair.
//here in this program we will search a number has how many co-prime factors.
static int GCD(int n , int a)
{
int gcd=0;
for(int i =1; i<=n && i<=a ; i++)
{
if(a%i==0 && n%i==0)
gcd=i;
}
return gcd;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int n = sc.nextInt();
int count =0;
for(int i =1;i<n;i++)
{
if(GCD(n,i)==1)
count++;
}
System.out.println(count+" no. of co-prime factors are there within the number "+n);
}
}