-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAmicable.java
More file actions
38 lines (38 loc) · 1.42 KB
/
Amicable.java
File metadata and controls
38 lines (38 loc) · 1.42 KB
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
33
34
35
36
37
38
/**Amicable Numbers
* The Greeks considered the pair of numbers 220 and 284 to be amicable or friendly numbers
* because the sum of the proper divisors of one of the numbers is the other number.
* The sum of the proper factors of 220 is 1 + 2 + 4 + 5 + 10 + 11 + 20 + 22 + 44 + 55 + 110 = 284
* The sum of the proper factors of 284 is 1 + 2 + 4 + 71 + 142 = 220
* Determine whether:
* a.60 and 84 are amicable numbers.
* b.1184 and 1210 are amicable numbers. */
import java.util.*;
public class Amicable
{
public int Indian(int x)
{
int i,c=0;
for(i=1;i<=x/2;i++)
if(x%i==0)
c+=i;
return(c);
}
public static void main(String args[])
{
int n,n1;
Scanner as=new Scanner(System.in);
Amicable as1=new Amicable();
System.out.println("\tThe Amicable Numbers Checking Program\n");
System.out.print("Enter the value of First Number : ");
n=as.nextInt();
System.out.print("Enter the value of Second Number : ");
n1=as.nextInt();
int l=String.valueOf(n).length();//STANISH STYLE TO FIND LENGTH~!
int l1=String.valueOf(n1).length();
System.out.println("\n\t\tOUTPUT");
if(l==l1 && as1.Indian(n)==n1 && as1.Indian(n1)==n)
System.out.println("\nThese Numbers "+n+" & "+n1+" are AMICABLE!");
else
System.out.println("\nThese Numbers "+n+" & "+n1+" are NOT AMICABLE!");
}
}