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[];
LL prime[]= {,,,,,,,,,,,,,,,};
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<<) || cnt>) return ;
if(p[cnt]!= && p[cnt]>cur)//当前的因数个数已经记录过且当时记录的数比当前枚举到的数要大,则替换此因数个数下的枚举到的数
p[cnt]=cur;
if(p[cnt]==)//此因数个数的数还没有出现过,则记录
p[cnt]=cur;
LL temp=cur;
for(int i=; i<=limit; i++) //枚举数
{
temp=temp*prime[k];
if(temp>(1LL<<)) return;
getartprime(temp,cnt*(i+),i,k+);
}
} void Init(){
getartprime(, , , );
for(int i = ; i <= ; i++){
if(p[*i] != && p[*i-] != ) p[i] = min(p[*i], p[*i-]);
else if(p[*i] != ) p[i] = p[*i];
else p[i] = p[*i - ];
} }
int main(){
int n;
Init();
while(scanf("%d", &n) == && n){
printf("%lld\n", p[n]);
}
}
HDUSTOJ-1558 Flooring Tiles(反素数)的更多相关文章
- HDU 4228 Flooring Tiles 反素数
推出了结论,万万没想到最后用搜索.. 还想dp来着.. #include <cstdio> #include <cstring> #include <iostream&g ...
- 【POJ2886】Who Gets the Most Candies?-线段树+反素数
Time Limit: 5000MS Memory Limit: 131072K Case Time Limit: 2000MS Description N children are sitting ...
- Prime & 反素数plus
题意: 求因数个数为n的最小正整数k. n<=10^9输出其唯一分解形式 SOL: 模拟题,一眼看过去有点惊讶...这不是我刚看过的反素数吗... 咦数据怎么这么大,恩搞个高精吧... 于是T了 ...
- BZOJ 1053 & 反素数
题意: 反素数,膜一篇GOD's Blog...http://blog.csdn.net/ACdreamers/article/details/25049767 此文一出,无与争锋... CODE: ...
- Who Gets the Most Candies?(线段树 + 反素数 )
Who Gets the Most Candies? Time Limit:5000MS Memory Limit:131072KB 64bit IO Format:%I64d &am ...
- BZOJ 3085: 反质数加强版SAPGAP (反素数搜索)
题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3085 题意:求n(<=10^100)之内最大的反素数. 思路: 优化2: i ...
- ZOJ-2562 More Divisors 反素数
题意:给定一个数N,求小于等于N的所有数当中,约数最多的一个数,如果存在多个这样的数,输出其中最大的一个. 分析:反素数定义:对于任何正整数x,其约数的个数记做g(x).例如g(1)=1,g(6)=4 ...
- 【bzoj1053】反素数
[bzoj1053]反素数 题意 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4.如果某个正整数x满足:g(x)>g(i) 0<i<x,则称x为反质数.例 ...
- 【BZOJ】【1053】【HAOI2007】反素数ant
搜索 经典搜索题目(其实是蒟蒻只会搜……vfleaking好像有更优秀的做法?) 枚举质数的幂,其实深度没多大……因为$2^32$就超过N了……而且质数不能取的太大,所以不会爆…… /******** ...
随机推荐
- ubuntu16.04 安装mysql
安装mysql 1.sudo apt-get install mysql-server 2.sudo apt install mysql-client 3.sudo apt install libmy ...
- python装饰器的简单理解
如果你接触 Python 有一段时间了的话,想必你对 @ 符号一定不陌生了,没错 @ 符号就是装饰器的语法糖. 装饰器的使用方法很固定: 先定义一个装饰函数(帽子)(也可以用类.偏函数实现) 再定义你 ...
- window7下docker toolbox 启用数据卷报错: Error response from daemon: invalid mode:
场景:希望把d:\dockerShare文件夹作为数据卷 ,和docker中的centos镜像生成的容器关联. 原来的命令: docker run -d -it --name=edc-centos7 ...
- ExoPlayer + 边缓存边播放
在此基础上改动:https://www.cnblogs.com/candyzhmm/p/9957928.html private void openPlayer(String videoUrl) { ...
- Java大文件上传详解及实例代码
1,项目调研 因为需要研究下断点上传的问题.找了很久终于找到一个比较好的项目. 在GoogleCode上面,代码弄下来超级不方便,还是配置hosts才好,把代码重新上传到了github上面. http ...
- 特征提取算法(2)——HOG特征提取算法
histogram of oriented gradient(方向梯度直方图)特征是一种在计算机视觉和图像处理中用来进行物体检测的特征描述子.它通过计算和统计图像局部区域的梯度方向直方图来构成特征.H ...
- JAVA-IO模型(BIO,NIO,AIO)
基本概念 阻塞和非阻塞 阻塞是进行读写时, 如果当时没有东西可读,或者暂时不可写, 程序就进入等待, 直到有东西可读或者可写为止 非阻塞是如果没有东西可读, 或者不可写, 读写函数马上返回, 而不会等 ...
- 阿里云CentOS 7.3安装Redis详细步骤
############ 准备 ############### 从Redis官网下载Linux redis3.2.6版本,我下载的redis-3.2.6.tar.gz(目前最新稳定版),下载到/u ...
- nodejs工作大全
1.修改文件夹中图片的名称 var fs = require('fs');var fileDirectory = "F:\\zdw\\修改文件夹名称\\newFile";var n ...
- SpringBoot:使用IDEA快速构建项目
西部开源-秦疆老师:基于SpringBoot 2.1.6 的博客教程 秦老师交流Q群号: 664386224 未授权禁止转载!编辑不易 , 转发请注明出处!防君子不防小人,共勉! SpringBoot ...