HDUSTOJ-1558 Flooring Tiles(反素数)

1558: Flooring Tiles

时间限制: 3 Sec  内存限制: 128 MB
提交: 59  解决: 36
[提交][状态][讨论版]

题目描述

You want to decorate your floor with square tiles. You like rectangles. With six square flooring tiles, you can form exactly two unique rectangles that use all of the tiles: 1 x 6, and 2 x 3 (6 x 1 is considered the same as 1 x 6. Likewise, 3 x 2 is the same as 2 x 3). You can also form exactly two unique rectangles with four square tiles, using all of the tiles: 1 x 4, and 2 x 2.

Given an integer N, what is the smallest number of square tiles needed to be able to make exactly N unique rectangles, and no more, using all of the tiles? If N = 2, the answer is 4.

输入

There will be several test cases in the input. Each test case will consist of a single line containing a single integer N,  which represents the number of desired rectangles. The input will end with a line with a single `0‘.

输出

For each test case, output a single integer on its own line, representing the smallest number of square flooring tiles needed to be able to form exactly N rectangles, and no more, using all of the tiles. The answer is guaranteed to be at most 1018. Output no extra spaces, and do not separate answers with blank lines.

样例输入

2
16
19
0

样例输出

4
840
786432
#include<iostream>
#include<cstring>
#include<cstdio>

using namespace std;
typedef long long LL;
LL p[1010];
LL prime[30]= {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
void getartprime(LL cur,int cnt,int limit,int k)
{
    //cur:当前枚举到的数;
    //cnt:该数的因数个数;
    //limit:因数个数的上限;2^t1*3^t2*5^t3……t1>=t2>=t3……
    //第k大的素数
    if(cur>(1LL<<60) || cnt>150) return ;
    if(p[cnt]!=0 && p[cnt]>cur)//当前的因数个数已经记录过且当时记录的数比当前枚举到的数要大,则替换此因数个数下的枚举到的数
        p[cnt]=cur;
    if(p[cnt]==0)//此因数个数的数还没有出现过,则记录
        p[cnt]=cur;
    LL temp=cur;
    for(int i=1; i<=limit; i++) //枚举数
    {
        temp=temp*prime[k];
        if(temp>(1LL<<60)) return;
        getartprime(temp,cnt*(i+1),i,k+1);
    }
}

void Init(){
    getartprime(1, 1, 75, 0);
    for(int i = 1; i <= 75; i++){
        if(p[2*i] != 0 && p[2*i-1] != 0) p[i] = min(p[2*i], p[2*i-1]);
        else if(p[2*i] != 0) p[i] = p[2*i];
        else p[i] = p[2*i - 1];
    }

}
int main(){
    int n;
    Init();
    while(scanf("%d", &n) == 1 && n){
        printf("%lld\n", p[n]);
    }
}
 
时间: 2024-08-07 16:39:24

HDUSTOJ-1558 Flooring Tiles(反素数)的相关文章

HDU 4228 Flooring Tiles 反素数

推出了结论,万万没想到最后用搜索.. 还想dp来着.. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <math.h> #include <set> #include <vector> #include <map> using namespace std; #define ll lon

HDU 4228 Flooring Tiles 反素数的应用

给你一个数N,找出一个最小的可以拆分成N种乘积表达形式的数x 比如N=2,6可以拆成2x3或者1x6两种,但不是最小的,最小的是4可以拆成1x4,2x2两种 首先可以肯定的是x必然有N*2或者是N*2-1(完全平方的情况)个约数 利用求反素数的过程求出约数为N*2和N*2-1个的最小的数 #include <cstdio> #include <sstream> #include <fstream> #include <cstring> #include &l

反素数 -- 数学

反素数就是区间内约数个数最多的那个数. 在ACM题目里, 一般是求约数最多而且数字最小的那个数,[1--n] 二是求约数刚好等于n的最小的那个数 三是求区间里的最小反素数[beign,end] 1和3有区别吗?有,1可以加速,3只能暴力 先说下思路 思路 : 官方题解 : (1)此题最容易想到的是穷举,但是肯定超时. (2)我们可以知道,计算约数的个数和质因数分解有着很大的联系: 若Q的质因数分解为:Q=p1^k1*p2^k2*…*pm^km(p1…pm为素数,k1…km≥1),则Q有(k1+1

反素数(暴力)

反素数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5194    Accepted Submission(s): 3043 Problem Description 反素数就是满足对于任意i(0<i<x),都有g(i)<g(x),(g(x)是x的因子个数),则x为一个反素数.现在给你一个整数区间[a,b],请你求出该区间的x

反素数深度分析

装载自:http://blog.csdn.net/ACdreamers/article/details/25049767 小知识点: 如果求约数的个数 756=2^2*3^3*7^1 (2+1)*(3+1)*(1+1)=24 基于上述结论,给出算法:按照质因数大小递增顺序搜索每一个质因子,枚举每一个质因子 为了剪枝: 性质一:一个反素数的质因子必然是从2开始连续的质数. 因为最多只需要10个素数构造:2,3,5,7,11,13,17,19,23,29 性质二:p=2^t1*3^t2*5^t3*7

poj 2886 Who Gets the Most Candies?(线段树+约瑟夫环+反素数)

Who Gets the Most Candies? Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 9934   Accepted: 3050 Case Time Limit: 2000MS Description N children are sitting in a circle to play a game. The children are numbered from 1 to N in clockwise o

【BZOJ 1053】 1053: [HAOI2007]反素数ant (反素数)

1053: [HAOI2007]反素数ant Description 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4.如果某个正整数x满足:g(x)>g(i) 0<i<x ,则称x为反质数.例如,整数1,2,4,6等都是反质数.现在给定一个数N,你能求出不超过N的最大的反质数么 ? Input 一个数N(1<=N<=2,000,000,000). Output 不超过N的最大的反质数. Sample Input 1000 Sample Output

[BZOJ 1053] [HAOI 2007]反素数ant

1053: [HAOI2007]反素数ant Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1857  Solved: 1034[Submit][Status][Discuss] Description 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4.如果某个正整数x满足:g(x)>g(i) 0<i<x,则称x为反质数.例如,整数1,2,4,6等都是反质数.现在给定一个数N,你能求出不超过N的最大的反质数么?

zoj2562--More Divisors(反素数模板)

More Divisors Time Limit: 2 Seconds      Memory Limit: 65536 KB Everybody knows that we use decimal notation, i.e. the base of our notation is 10. Historians say that it is so because men have ten fingers. Maybe they are right. However, this is often