zoukankan      html  css  js  c++  java
  • codeforces 27E Number With The Given Amount Of Divisors

    E. Number With The Given Amount Of Divisors
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018.

    Input

    The first line of the input contains integer n (1 ≤ n ≤ 1000).

    Output

    Output the smallest positive integer with exactly n divisors.

    Sample test(s)
    input
    4
    output
    6
    input
    6
    output
    12

    题目描述是给你一个n,表示一个数有n个约数,要求你求出这个数最小是多少。
    在做着个题目之前,我是做了hdu4542这个题目,然后在大牛的微博上看到了题目推荐才去做的。
    这个题目和hdu4542很想,它的代码则是属于hdu4542中的一部分。
    解题思路其实是,将一个数m做质因数分解后,我们可以将m写成m=p1^a1*p2^a2*p3^a3...pn^an;
    难么m的约数的个数就可以写成是(1+a1)*(1+a2)*(1+a3)...*(1+an);
    然后用dfs枚举所有可能的组合打成表记录一下。

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    using namespace std;
    const int maxn=100000;
    const long long inf=(1LL<<60)+1;
    int prime[maxn+10];
    bool check[maxn+10];
    int tot;
    int N;
    void getprime()
    {
    tot=0;
    memset(check,false,sizeof(check));
    for(int i=2;i<=maxn;i++)
    {
    if(!check[i])
    prime[tot++]=i;
    for(int j=0;j<tot;j++)
    {
    if(i*prime[j]>maxn)
    break;
    check[prime[j]*i]=true;
    if(i%prime[j]==0)
    break;
    }
    }
    }
    long long a[1010];
    void dfs(int i,long long x,int n)//这里的三个参数的含义:i表示prime数组中对应素数的标号,x表示的是要求解的答案,n表示的是约数的个数。
    {
    if(n>1000)
    return;
    if(x<inf&&(a[n]>x||a[n]==0))
    a[n]=x;
    for(int j=1;j<=60;j++)
    {
    if(inf/prime[i]<x)
    break;
    x*=prime[i];
    if(x>=inf)
    break;
    dfs(i+1,x,n*(j+1));
    }
    }
    void init()
    {
    memset(a,0,sizeof(a));
    dfs(0,1,1);
    }
    int main()
    {
    getprime();
    init();
    while(scanf("%d",&N)!=EOF)
    {
    printf("%I64d ",a[N]);
    }
    return 0;
    }

  • 相关阅读:
    Maker DAO 与稳定币 Dai
    0x 协议治理体系,Part-2:Q&A
    Gnosis白皮书
    Digix:密码学资产中的黄金标准
    闪电网络主心骨——HTLC(哈希时间锁定)简介
    如何减少PDF文件的大小
    以太坊:创建 ERC-20 token
    Sublime Text 3 快捷键大全
    数据库学习第二季第三集:各种编程语言从数据库中获得数据方式小结
    数据库学习第二季第三集:各种编程语言从数据库中获得数据方式小结
  • 原文地址:https://www.cnblogs.com/hbutACMER/p/4709083.html
Copyright © 2011-2022 走看看