Algorithms for finding intimacy Pairs

Source: Internet
Author: User

Number of intimacy Pairs Algorithm
  1. /** 
  2. * An Algorithm for Finding intimacy pairs. <Br> 
  3. * 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. 
  4. * @ Author Zhao Xueqing java2000.net 
  5. */
  6. Public ClassT {
  7. Public Static VoidMain (string [] ARGs ){
  8. IntNum;
  9. For(IntI =2; I <=1000; I ++ ){
  10. Num = getdivnumber (I );
  11. If(Num> I ){
  12. If(Getdivnumber (Num) = I ){
  13. System. Out. println (I +"/"+ Num );
  14. }
  15. }
  16. }
  17. }
  18. Public Static IntGetdivnumber (IntI ){
  19. IntTotal =1;
  20. IntTo = (Int) Math. SQRT (I );
  21. For(IntJ =2; J <= to; j ++ ){
  22. If(I % J =0){
  23. Total + = J;
  24. If(J! = I/J ){
  25. Total + = I/J;
  26. }
  27. }
  28. }
  29. ReturnTotal;
  30. }
  31. }
 
/*** 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.