zoukankan      html  css  js  c++  java
  • hdu3189-Just Do It-(埃氏筛+唯一分解定理)

    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.
     
    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
    翻译:输入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+5;
    
    int cnt[maxx];///下标是自然数,内容是这个自然数有多少个因子
    int ans[maxx];///下标是因子数,内容是含有这么多因子数最小是哪个数
    
    void init()//埃氏筛打表
    {
        memset(ans,-1,sizeof(ans));
        memset(cnt,0,sizeof(cnt));
        for(int i=1;i<maxx;i++)
        {
            for(int j=i;j<maxx;j=j+i)
            {
                cnt[j]++;
            }
            if( ans[ cnt[i] ]==-1 )///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]>1000)
                printf("-1
    ");
            else
                printf("%d
    ",ans[n]);
        }
        return 0;
    }
  • 相关阅读:
    wnmpa或lnmpa 服务器搭建和原理
    windows 桌面图标 隐藏 小盾牌标志
    C# 执行 CMD 终极稳定解决方案
    比较两个object是否相等
    Microsoft Store 加载失败
    ORA-12514: TNS:监听程序当前无法识别连接描述符中请求的服务
    Win10安装gcc、g++、make
    通过proxifier实现酸酸乳全局代理
    C# 字母转数字
    html中设置锚点定位的几种常见方法(#号定位)
  • 原文地址:https://www.cnblogs.com/shoulinniao/p/10357512.html
Copyright © 2011-2022 走看看