Number of intimacy Pairs Algorithm
-
- /**
-
- * An Algorithm for Finding intimacy pairs. <Br>
-
- * If the factor of A is equal to B, the factor of B is equal to a, and the factor of B is equal to a, and a is equal to B, then A and B are called intimacy pairs.
-
- *
-
- * @ Author Zhao Xueqing java2000.net
-
- */
-
- Public ClassT {
- Public Static VoidMain (string [] ARGs ){
-
- IntNum;
-
- For(IntI =2; I <=1000; I ++ ){
-
- Num = getdivnumber (I );
- If(Num> I ){
-
- If(Getdivnumber (Num) = I ){
-
- System. Out. println (I +"/"+ Num );
-
- }
-
- }
-
- }
-
- }
-
- Public Static IntGetdivnumber (IntI ){
-
- IntTotal =1;
-
- IntTo = (Int) Math. SQRT (I );
-
- For(IntJ =2; J <= to; j ++ ){
- If(I % J =0){
-
- Total + = J;
-
- If(J! = I/J ){
-
- Total + = I/J;
-
- }
-
- }
-
- }
- ReturnTotal;
-
- }
-
- }
/*** The search algorithm of the intimate number pair. <Br> * If the sum of A and B is equal to B, the sum of B is equal to a, and a is equal to B,, B is an intimate number pair ** @ author Zhao Xueqing java2000.net */public class t {public static void main (string [] ARGs) {int num; For (INT I = 2; I <= 1000; I ++) {num = getdivnumber (I); If (Num> I) {If (getdivnumber (Num) = I) {system. out. println (I + "/" + num) ;}}} public static int getdivnumber (int I) {int Total = 1; int to = (INT) math. SQRT (I); For (Int J = 2; j <= to; j ++ ) {If (I % J = 0) {total + = J; If (J! = I/J) {total + = I/J ;}} return total ;}}
running result
220/284