
Just Do It
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1552 Accepted Submission(s):
1036
Problem Description
Now we define a function F(x), which means the factors
of x. In particular, F(1) = 1,since 1 only has 1 factor 1, F(9) = 3, since 9 has
3 factors 1, 3, 9. Now give you an integer k, please find out the minimum number
x that makes F(x) = k.
of x. In particular, F(1) = 1,since 1 only has 1 factor 1, F(9) = 3, since 9 has
3 factors 1, 3, 9. Now give you an integer k, please find out the minimum number
x that makes F(x) = k.
Input
The first line contains an integer t means the number
of test cases.
The follows t lines, each line contains an integer k. (0 <
k <= 100).
of test cases.
The follows t lines, each line contains an integer k. (0 <
k <= 100).
Output
For each case, output the minimum number x in one line.
If x is larger than 1000, just output -1.
If x is larger than 1000, just output -1.
Sample Input
4
4
2
5
92
4
2
5
92
Sample Output
6
2
16
-1
2
16
-1
翻译:输入k,求因子数为k的数最小是哪个。
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<vector>
#include<iostream>
#include<cstring>
#define inf 0x3f3f3f3f
using namespace std;
#define ll long long
const int maxx=1e6+; int cnt[maxx];///下标是自然数,内容是这个自然数有多少个因子
int ans[maxx];///下标是因子数,内容是含有这么多因子数最小是哪个数 void init()//埃氏筛打表
{
memset(ans,-,sizeof(ans));
memset(cnt,,sizeof(cnt));
for(int i=;i<maxx;i++)
{
for(int j=i;j<maxx;j=j+i)
{
cnt[j]++;
}
if( ans[ cnt[i] ]==- )///i从1开始,越变越大,因子数也会越来越多
ans[ cnt[i] ]=i;///ans的下标 第一次遇见 没有遇见过的因子数目,就把i传进去,此时的i最小
}
} int main()///hdu3189
{
init();
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
if(ans[n]>)
printf("-1\n");
else
printf("%d\n",ans[n]);
}
return ;
}