您的位置:首页 > 其它

hdu---------3189-------------------

2016-01-12 18:22 260 查看
水体一个,但是这种做题的方法值得发扬光大............

Just Do It

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1122    Accepted Submission(s): 743

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.

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).

Output
For each case, output the minimum number x in one line. If x is larger than 1000, just output -1.

Sample Input
4
4
2
5
92

Sample Output
6
2
16
-1


意思大概是,,,,,,9的因子都有1 3 9 三个数字 4也有三个因子 现在输入一个3 你需要输出 4(因为4 是有三个因子的数字中最小的数字)....意思就是这 很简单打表遍历,,,,但是 遍历的时候想到了,,, 如果倒序 遍历的话,例如 便利到9发现有3个因子,

这时候数组赋值为 a[3]=9; 然后一会有到4了,也是4个因子 在此进行赋值 a[3]=4; 这样的话,,简单又弱智

#include<stdio.h>
#include<string.h>
int main()
{
int q,i,j,m,n,t,a[1001],b,c;
memset(a,0,sizeof(a));
for(i=1000;i>0;i--)
{
q=0;
for(j=i;j>0;j--)
{
if(i%j==0)
q++;
}
a[q]=i;
}
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
m=a
;
if(m==0)
m=-1;
printf("%d\n",m);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: