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