# Friends number（数论，打表）

xiaoxiao2021-03-26  10

## Friends number

Time limit     1000 ms             Memory limit       131072 kB

Paula and Tai are couple. There are many stories between them. The day Paula left by airplane, Tai send one message to telephone 2200284, then, everything is changing… (The story in “the snow queen”).

After a long time, Tai tells Paula, the number 220 and 284 is a couple of friends number, as they are special, all divisors of 220’s sum is 284, and all divisors of 284’s sum is 220. Can you find out there are how many couples of friends number less than 10,000. Then, how about 100,000, 200,000 and so on.

The task for you is to find out there are how many couples of friends number in given closed interval [a,b]

Input There are several cases. Each test case contains two positive integers a, b(1<= a <= b <=5,000,000). Proceed to the end of file. Output For each test case, output the number of couples in the given range. The output of one test case occupied exactly one line. Sample Input 1 100 1 1000 Sample Output 0 1

题解：先给一个定义：夫妻数，a,b,1至a（不包括a）的所有除数之和为b,反之b的除数之和也为a,则称aa,b为夫妻数……求AB之间的夫妻数的个数……

告诉你个秘密，别看数据范围为5000000，其实打表到500000就可以了……

#include<stdio.h> #include<iostream> #include<algorithm> #include<string.h> #include<stdlib.h> #include<time.h> #include<string> #include<math.h> #include<map> #include<queue> #include<stack> #define INF 0x3f3f3f3f #define ll long long #define For(i,a,b) for(int i=a;i<b;i++) #define sf(a) scanf("%d",&a) #define sfs(a) scanf("%s",a) #define sff(a,b) scanf("%d%d",&a,&b) #define pf(a) printf("%d\n",a) #define mem(a,b) memset(a,b,sizeof(a)) using namespace std; struct node { int aaa,bbb; }x[100]; int v[5100005]={0}; void fun() { for(int i=1;i<=2500000;i++) for(int j=2*i;j<=5000000;j+=i) v[j]+=i; int p=0; for(int i=1;i<=5000000;i++) { if(v[i]!=i&&v[i]<=5000000&&v[v[i]]==i&&v[i]>i) { x[p].aaa=i; x[p].bbb=v[i]; p++; } } } int main() { fun(); int aa,bb; while(~sff(aa,bb)) { int ans=0; for(int i=0;i<100;i++) { if(x[i].aaa>=aa&&x[i].bbb<=bb) ans++; } printf("%d\n",ans); } }

#include <stdio.h> #include <stdlib.h> int Ans[56][2]={ 220,284, 1184,1210, 2620,2924, 5020,5564, 6232,6368, 10744,10856, 12285,14595, 17296,18416, 63020,76084, 66928,66992, 67095,71145, 69615,87633, 79750,88730, 100485,124155, 122265,139815, 122368,123152, 141664,153176, 142310,168730, 171856,176336, 176272,180848, 185368,203432, 196724,202444, 280540,365084, 308620,389924, 319550,430402, 356408,399592, 437456,455344, 469028,486178, }; int main(){ int a,b,ans,i; while(scanf("%d %d",&a,&b)!=EOF){ ans=0; for(i=0;i<56;i++) if(a<=Ans[i][0]&&Ans[i][1]<=b) ans++; printf("%d\n",ans); } return 0; }