Description
On the Chinese Valentine's day, Yuelao came to the digital kingdom. He posted a notice on the gate of the city, and said to the people of the digital Kingdom, "do you want to know who your other half is? Go to find it according to the way on the notice!" people came to the notice one after another, all of them want to know who their other half is. The notice is as follows:
The factor of number n is all positive integers smaller than N and divisible by N. for example, the factor of 12 has 1,2,3,4,6. Do you want to know your other half?
Input
The first row of input data is a number T (1 < = T < = 500000), which indicates the number of groups of test data. Then there is a group t test data, each group of test data has only one number n (1 < = n < = 500000)
Output
For each group of test data, please output a number representing the other half of input data N
Sample Input
3 2 10 20
Sample Output
1 8 22
Hint
Problem solving: using the idea of prime number table to find the factors of n to accumulate and store in the array. (pay attention to cacin
The code is as follows:
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<cmath> #include<map> #include<stack> #include<vector> #include<queue> #include<set> #include<algorithm> #define max(a,b) (a>b?a:b) #define min(a,b) (a<b?a:b) #define swap(a,b) (a=a+b,b=a-b,a=a-b) #define X (sqrt(5)+1)/2.0 #define maxn 320007 #define N 100000000 #define INF 0x3f3f3f3f #define PI acos(-1) #define lowbit(x) (x&(-x)) #define read(x) scanf("%d",&x) #define put(x) printf("%d\n",x) #define memset(x,y) memset(x,y,sizeof(x)) #define Debug(x) cout<<x<<" "<<endl #define lson i << 1,l,m #define rson i << 1 | 1,m + 1,r #define mod 1000000009 #define e 2.718281828459045 #define eps 1.0e18 #define ll long long using namespace std; int a[500007]; int main() { for(int i=2;i<=500000;i++) a[i]=1; for(int i=2;i<=250000;i++) { for(int j=2;i*j<=500000;j++) a[j*i]+=i; } int n; scanf("%d",&n); while(n--) { int m; scanf("%d",&m); printf("%d\n",a[m]); } return 0; }