Algorithm---number theory 2---intimacy

Source: Internet
Author: User
Tags stdin

Algorithm---number theory 2---intimacy

If the factor of the integer A and equals the integer B, the factor of the integer b and equals the integer A, the factor includes 1 but does not include itself, and a is not equal to B, then A and b are the pairs of intimacy.

1 /*2 title: Intimacy Number3 author Taoliu--alex 2016.104 5 The main realization of two6 1 Determine whether two digits are not intimate numbers. 7 2 Find out the number of intimacy within a certain range. 8 9 */Ten  One  A#include <stdio.h> -#include <stdlib.h> -  the intFriendnum (intAintb); - intFactor_sum (intn); - voidScope_friendnum (intscope); -  + //determine whether the two digits are not intimate numbers.  -  + intFriendnum (intAintb) A { at     if(a==b) -     { -         return-1; -     } -     inta_sum=0; -     intb_sum=0; ina_sum=Factor_sum (a); -b_sum=Factor_sum (b); to     //printf ("The factor sum of%d is%d\n", a,a_sum); +     //printf ("The factor sum of%d is%d\n", b,b_sum); -     if((a_sum==b) && (b_sum==a)) the     { *         return 1; $     }Panax Notoginseng     Else -     { the         return 0; +     } A  the } +  - intFactor_sum (intN) $ { $     intsum=0; -      for(inti =1; I < n/2+1; i++) -     { the         if(n%i==0) -         {Wuyisum=sum+i; the         } -     } Wu     returnsum; - } About  $ //find out the number of intimacy within a certain range.  - voidScope_friendnum (intscope) - { -      for(inti =1; I < scope; i++) A     { +          for(intj = i; J < Scope; J + +) the         { -             intans=Friendnum (i,j); $             if(ans==1) theprintf"%d and%d is friendnum\n", i,j); the         } the     } the } -  in  the intMain () the { About     intjudge; the     intA,b,scope; theprintf"What are want to do:0 means judge, number is friendnum or not;\n"); theprintf"1 means want to find the Friendnum in scope\n"); +     //fflush (stdin); -scanf"%d",&judge); the     if(judge==0)Bayi     { theprintf"input want to judge!\n"); the         //fflush (stdin); -scanf"%d%d",&a,&b); -         intans=Friendnum (A, b); the         if(ans==1) the         { theprintf"%d and%d is friendnum\n", A, b); the         } -         if(ans==0) the         { theprintf"%d and%d are not friendnum\n", A, b); the         }94         Else theprintf"%d and%d is the same number, error!\n", A, b); the     } the     if(judge==1)98     { Aboutprintf"input the scope you want to find\n"); -         //fflush (stdin);101scanf"%d",&scope);102 Scope_friendnum (scope);103     }104     return 0; the}

Algorithm---number theory 2---intimacy

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.