http://acm.hdu.edu.cn/showproblem.php?pid=4542

给出一个数K和两个操作

如果操作是0,就求出一个最小的正整数X,满足X的约数个数为K。

如果操作是1,就求出一个最小的X,满足X的约数个数为X-K。

对于操作0,分析见这里,搜索需要有力剪枝。对于操作1,代表1至X中不是X的约数个数为K,看似还是搜索,但是由于时限卡的丧心病狂...所以用打表完成

d[i]先用来表示i的约数个数,然后可以模仿素数打表,对于每个数的每个倍数,其d值都自减1,这样就求出每个i对应的d[i](非约数个数)

又由于然后对于i来讲,一定有d[i]<i,那么我们只需在求d[i]的过程中将其映射关系调换为指定非约数个数的最小的数,方法就是

if(!d[d[i]]) d[d[i]] = i;
d[i] = 0;

仔细想想这两句话的意思!

#pragma comment(linker, "/STACK:36777216")
#pragma GCC optimize ("O2")
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define clr0(x) memset(x,0,sizeof(x))
#define eps 1e-9
const double pi = acos(-1.0);
typedef long long LL;
typedef unsigned long long ULL;
const int modo = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int maxn = 1005,N = 50000;
int n,pr[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
LL ans;
int d[N]; void Init()
{
for(int i = 1;i < N;i++) d[i] = i;
for(int i = 1;i < N;i++)
{
for(int j = i;j < N;j += i) d[j]--;
if(!d[d[i]]) d[d[i]] = i;
d[i] = 0;
}
// for(int i = 1;i < 100;++i){
// cout<<i<<':'<<d[i]<<endl;
// }
}
void dfs(int dep,int cnt,LL res)
{
if(cnt > n)
return;
if(cnt == n){
ans = min(ans,res);
return ;
}
for(int i = 1;i <= 62;++i){
if(res > ans/pr[dep] || cnt*(i+1) > n)
break;
res *= pr[dep];
if(n % (cnt*(i+1)) == 0)
dfs(dep+1,cnt*(i+1),res);
}
}
int main(){
Init();
int _,cas = 1;RD(_);
while(_--){
int type;
RD2(type,n);
if(type)
ans = d[n];
else{
ans = 1LL<<62;
dfs(0,1,1);
}
printf("Case %d: ",cas++);
if(ans == 0) puts("Illegal");
else if(ans >= 1LL<<62) puts("INF");
else printf("%I64d\n",ans);
}
return 0;
}

hdu 4542 打表+含k个约数最小数的更多相关文章

  1. Codeforces Beta Round #27 E. Number With The Given Amount Of Divisors 含n个约数最小数

    http://codeforces.com/problemset/problem/27/E RT,求含n个约数的最小的数 我们设答案p = 2^t1 * 3^t2 * -- * p^tk(其中p是第k ...

  2. POJ C程序设计进阶 编程题#1:含k个3的数

    编程题#1:含k个3的数 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 输 ...

  3. hdu 5008 查找字典序第k小的子串

    Boring String Problem Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  4. HDU 5726 GCD 区间GCD=k的个数

    GCD Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  5. hdu 4542 数论 + 约数个数相关 腾讯编程马拉松复赛

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4542 小明系列故事--未知剩余系 Time Limit: 500/200 MS (Java/Others) ...

  6. hdu 4542 小明系列故事——未知剩余系 反素数 + 打表

    小明系列故事——未知剩余系 Time Limit: 500/200 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Prob ...

  7. hdu 5019(第K大公约数)

    Revenge of GCD Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  8. HDU 1223 打表 + 大数

    http://acm.hdu.edu.cn/showproblem.php?pid=1223 一般遇到这些题,我都是暴力输出前几项,找规律.未果. 然后输出n = 1时候,以A开始,有多少个答案, n ...

  9. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. C# 通过api函数GetPrivateProfileString读取ini文件,取不到值

    通过api函数GetPrivateProfileString读取ini文件,取不到值,测试了好长时间,都不行 确认程序,ini文件都没有错误的情况,最后发现是ini文件编码的原因. 将ini文件的编码 ...

  2. LINUX查看网卡UUID

    有时我们不小心将/etc/sysconfig/network-scripts/ifcfg-eth0(可以通过此文件进行查看UUID)删除或者损坏,要重新编辑ifcfg-eth0文件时不知道网卡的UUI ...

  3. java byte转string 涉及到字节流中有中文

    最近遇到一个问题,我用java写了一个客户端通过socket向服务器端发送消息,发送的内容是字节流,编码格式是GBK,服务器在收到消息后,如果格式正确,会返回固定的消息格式,同样也是字节流,编码格式也 ...

  4. 爬虫初窥day2:正则

    正则在线测试 http://tool.oschina.net/regex https://www.regexpal.com/ http://tool.chinaz.com/regex exp1:筛选所 ...

  5. nginx域名转发 负载均衡 反向代理

    公司有三台机器在机房,因为IP不够用,肯定要分出来,所以要建立单IP 多域名的反向代理, 就是当请求www.abc.com 跳转到本机, 请求www.bbc.com 跳转到192.168.0.35 机 ...

  6. Maximum Swap LT670

    Given a non-negative integer, you could swap two digits at most once to get the maximum valued numbe ...

  7. centos安装tomcat7.0.70

    抄自:https://www.cnblogs.com/www1707/p/6592504.html apache-tomcat-7.0.70jdk-7u67-linux-x64 下载tomcathtt ...

  8. Controller异步模式

    转载: https://blog.csdn.net/yingxiake/article/details/51193319 因为服务器请求处理线程的总数是有限的,如果类似的请求多了,所有的处理线程处于阻 ...

  9. Centos上安装phpmyadmin

    查看PHP有没有安装:php -v查看apache有没有安装:httpd -v如已经安装则想办法删除. 一.安装Apache(默认安装目录etc/httpd/) 1. 使用yum命令安装Apache ...

  10. XML 解析的两种方法

    申请博客有一段时间了,一直没有写些什么,今天写一下被遗忘的 xml,因为 ios 现在一般都用 JSON,但毕竟还有一部分老一些的服务器还会有 xml xml 格式的解析方式有两种 1.SAX解析: ...