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(反素数)的更多相关文章

  1. HDU 4228 Flooring Tiles 反素数

    推出了结论,万万没想到最后用搜索.. 还想dp来着.. #include <cstdio> #include <cstring> #include <iostream&g ...

  2. 【POJ2886】Who Gets the Most Candies?-线段树+反素数

    Time Limit: 5000MS Memory Limit: 131072K Case Time Limit: 2000MS Description N children are sitting ...

  3. Prime & 反素数plus

    题意: 求因数个数为n的最小正整数k. n<=10^9输出其唯一分解形式 SOL: 模拟题,一眼看过去有点惊讶...这不是我刚看过的反素数吗... 咦数据怎么这么大,恩搞个高精吧... 于是T了 ...

  4. BZOJ 1053 & 反素数

    题意: 反素数,膜一篇GOD's Blog...http://blog.csdn.net/ACdreamers/article/details/25049767 此文一出,无与争锋... CODE: ...

  5. Who Gets the Most Candies?(线段树 + 反素数 )

    Who Gets the Most Candies? Time Limit:5000MS     Memory Limit:131072KB     64bit IO Format:%I64d &am ...

  6. BZOJ 3085: 反质数加强版SAPGAP (反素数搜索)

    题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3085 题意:求n(<=10^100)之内最大的反素数. 思路: 优化2: i ...

  7. ZOJ-2562 More Divisors 反素数

    题意:给定一个数N,求小于等于N的所有数当中,约数最多的一个数,如果存在多个这样的数,输出其中最大的一个. 分析:反素数定义:对于任何正整数x,其约数的个数记做g(x).例如g(1)=1,g(6)=4 ...

  8. 【bzoj1053】反素数

    [bzoj1053]反素数 题意 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4.如果某个正整数x满足:g(x)>g(i) 0<i<x,则称x为反质数.例 ...

  9. 【BZOJ】【1053】【HAOI2007】反素数ant

    搜索 经典搜索题目(其实是蒟蒻只会搜……vfleaking好像有更优秀的做法?) 枚举质数的幂,其实深度没多大……因为$2^32$就超过N了……而且质数不能取的太大,所以不会爆…… /******** ...

随机推荐

  1. JOI2019 有趣的家庭菜园3

    问题描述 家庭菜园专家 JOI 先生在他的家庭菜园中种植了一种叫 Joy 草的植物.在他的菜园里,有 N 个花盆自东向西摆放,编号分别为 \(1, \ldots, N\).每个花盆中有一株 Joy 草 ...

  2. LeetCode--079--单词搜索(python)

    给定一个二维网格和一个单词,找出该单词是否存在于网格中. 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格.同一个单元格内的字母不允许被重复使用. ...

  3. vue+elementUI 做的递归组件

    废话少说,直接上最新鲜的干货 当然,你得提前安装好bootstrap,router,element-ui,vue-axios 1.上递归组件,此处参考了某位大神的代码,具体不知道是谁,因为到处都有人用 ...

  4. logstash+redis收集负载均衡模式下多台服务器的多个web日志

    一.logstash的简介 一般我们看日志来解决问题的时候要么 tail+grep 要么 把日志下载下来再搜索,可以应付不多的主机和应用不多的部署场景.但对于多机多应用部署就不合适了.这里的多机多应用 ...

  5. SpringMVC最新教程IDEA版

    1.servlet项目结构与识别 Idea里带个蓝点的文件夹为tomcat吃的网站内容,idea会通过“Web Resource Directory”来标注,会被打成一个war包 这个文件夹里,MET ...

  6. css-按钮中有图片和文字,怎么才能让文字和图片都中??

    <div class="btn1 trans" > <img src="../../images/img/add.png"/> < ...

  7. Python3 实现FTP功能

    目录结构: FTP_project/ ├── FTP_client │   ├── ftp_client.py │   └── __init__.py └── FTP_server ├── bin │ ...

  8. ckeditor实现WORD粘贴图片自动上传,jsp应用

    官网地址http://ueditor.baidu.com Git 地址 https://github.com/fex-team/ueditor 参考博客地址 http://blog.ncmem.com ...

  9. (8)Linux(客户端)和Windows(服务端)下socket通信实例

    Linux(客户端)和Windows(服务端)下socket通信实例: (1)首先是Windows做客户端,Linux做服务端的程序 Windows   Client端 #include <st ...

  10. codeforces D Salary Changing

    题意:给你n个人,和s块钱,每个人都有一个工资区间,你给所有人都发工资.然后要他们工资的中位数最大. 思路:二分找那个值.那个值要满足至少有n/2+1个工资区间内. #include<cstdi ...