Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

Betrothed Numbers in MATLAB


Definition:

Betrothed numbers are two positive numbers such that the sum of the proper divisors of either number is one more than (or one plus) the value of the other number. Our task is to find these pairs efficiently.

Example 1:

(48, 75) is an example of Betrothed numbers
Divisors of 48 : 1, 2, 3, 4, 6, 8, 12,
                 16, 24. Their sum is 76.
Divisors of 75 : 1, 3, 5, 15, 25. Their
                 sum is 49.

Example 2: 140 ,195

MATLAB CODE:

x=input('Enter the number'); y=input('Enter the second number'); c=0; d=0; for i=1:x-1 if(rem(x,i)==0) c=c+i; end end for i=1:y-1 if(rem(y,i)==0) d=d+i; end end if(c==y+1 && d==x+1) disp('Yes'); else disp('No'); end

Explanation:


JAVA CODE:

import java.util.Scanner; class Bi { public static void main(String arsg[]) { Scanner obj=new Scanner(System.in); System.out.println("Enter the first number:"); int x=obj.nextInt(); System.out.println("Enter the second number:"); int y=obj.nextInt(); int c=0; int d=0; for(int i=1;i<=(x-1);i++) { if((x%i)==0) { c=c+i; } } for(int i=1;i<=(y-1);i++) { if((y%i)==0) { d=d+i; } } if((c==y+1) && (d==x+1)) { System.out.println("Yes"); } else { System.out.println("No"); } } }
OUTPUT:

No comments

Popular Posts

Followers