UVA 1575 Factors

https://vjudge.net/problem/UVA-1575

题意:

令f(k)=n 表示 有n种方式,可以把正整数k表示成几个数的乘积的形式。

例 10=2*5=5*2,所以f(10)=2

给出n,求最小的k

搜索

从最小的质数开始枚举选几个

假设前i-1个种质数用了k个,有sum种方案,第i种质数选a个,

那么前i种质数的方案就有sum*C[k+a][a]

可以理解原来有k个位置,又加了a个位置,有a个数可以放在任意位置

所以前i种的每一种方案都变成C[k+a][a]种

枚举每个质数选几个时,如果上一个质数选了k个,那么这一个质数最多选k个

假设这个质数选了k+1个,那么显然上一个质数选k+1个,这个选k个更优

注意整数类型上限

#include<cstdio>
#include<iostream>
using namespace std;
typedef unsigned long long LL;
int p[21]={0,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
LL ans,n;
LL C[70][70];
void solve(int num,int lim,LL tot,LL now,int last)
{
    if(now>ans) return;
    if(tot==n) { ans=now; return ; }
    if(tot>n || num>20) return;
    LL t=1;
    for(int i=1;i<=lim;i++)
    {
        t*=p[num];
        if(now>=ans/t) return;
        solve(num+1,i,tot*C[last+i][i],now*t,last+i);
    }
}
int main()
{
    C[0][0]=1;
    for(int i=1;i<70;i++)
    {
        C[i][0]=1;
        for(int j=1;j<=i;j++)
            C[i][j]=C[i-1][j-1]+C[i-1][j];
    }

    while(scanf("%lld",&n)!=EOF)
    {
        if(n==1)
        {
            printf("1 2\n");
            continue;
        }
        ans=(LL)1<<63;
        solve(1,63,1,1,0);
        printf("%lld %lld\n",n,ans);
    }
}
时间: 2024-12-18 23:11:32

UVA 1575 Factors的相关文章

UVA 160 - Factors and Factorials

 Factors and Factorials  The factorial of a number N (written N!) is defined as the product of all the integers from 1 to N. It is often defined recursively as follows: Factorials grow very rapidly--5! = 120, 10! = 3,628,800. One way of specifying su

UVA - 884 Factorial Factors

题目: 这个题目,我先开始尝试直接求出每个素因子的次数,然后全部加起来. 代码: #include<iostream> using namespace std; int degree_in_fact(int m, int p) { if (m)return degree_in_fact(m / p, p) + m / p; return 0; } bool isprime(int n) { if (n == 2)return true; if (n % 2 == 0)return false;

UVa 11621 - Small Factors

题目:找到不小于给定数n的,仅以2,3为因数组成的数字. 分析:数论,贪心,分治. 利用两根指针,分别代表乘2,与乘3的队列,队列为至今生成的数字,初始为{1}: 然后,每取两个指针对应元素*2和*3的值中最小的即为未找到的数字中最小的: 注意,可能生成重复数据,不要存进去(重复数据,一定连续产生). 说明:打表计算,二分查询输出即可. #include <iostream> #include <cstdlib> #include <cstdio> using name

UVA - 10791 - Minimum Sum LCM (数论相关!)

题目链接:Minimum Sum LCM UVA - 10791 Minimum Sum LCM Time Limit:3000MS   Memory Limit:Unknown   64bit IO Format:%lld & %llu SubmitStatus Description  Minimum Sum LCM  LCM (Least Common Multiple) of a set of integers is defined as the minimum number, whic

uva 11610 Reverse Prime

Problem FReverse Prime Input: Standard Input Output: Standard Output There are a few 7 digit positive numbers whose reverse number is a prime number and less than 10^6.  For example: 1000070, 1000090 and 1000240 are first few reverse prime numbers be

UVA 136 Ugly Numbers

原题代号:UVA 136 原题链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=72 题目原题: Ugly Numbers Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5,

UVA - 586 Instant Complexity

Description  Instant Complexity  Analyzing the run-time complexity of algorithms is an important tool for designing efficient programs that solve a problem. An algorithm that runs in linear time is usually much faster than analgorithm that takes quad

UVA 10168 Summation of Four Primes(数论)

Summation of Four Primes Input: standard input Output: standard output Time Limit: 4 seconds Euler proved in one of his classic theorems that prime numbers are infinite in number. But can every number be expressed as a summation of four positive prim

UVA 136 &amp; POJ1338 Ugly Numbers

题目大意: Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, - shows the first 10 ugly numbers. By convention, 1 is included. 把只含有2.3.5因数的数称为丑数,默认第一个丑数是1. POJ是有多次询问,输出第n个丑数 UVA是询问第1500个丑数是多少. 思路: