The time of a day

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 1297    Accepted Submission(s): 594

Problem Description
There are no days and nights on byte island, so the residents here can hardly determine the length of a single day. Fortunately, they have invented a clock with several pointers. They have N pointers which can move round the clock. Every pointer ticks once per second, and the i-th pointer move to the starting position after i times of ticks. The wise of the byte island decide to define a day as the time interval between the initial time and the first time when all the pointers moves to the position exactly the same as the initial time.
The wise of the island decide to choose some of the N pointers to make the length of the day greater or equal to M. They want to know how many different ways there are to make it possible.
 
Input
There are a lot of test cases. The first line of input contains exactly one integer, indicating the number of test cases.
  For each test cases, there are only one line contains two integers N and M, indicating the number of pointers and the lower bound for seconds of a day M. (1 <= N <= 40, 1 <= M <= 263-1)
 
Output
For each test case, output a single integer denoting the number of ways.
 
Sample Input
3
5 5
10 1
10 128
 
Sample Output
Case #1: 22
Case #2: 1023
Case #3: 586
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  4027 4022 4023 4026 4021 
 

#include<map>
#include<cstdio>
using namespace std;
typedef long long ll;
map<ll,ll>f[];ll m,ans;int n,cas,Cas;
map<ll,ll>::iterator it,ii;
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int main(){
f[][]=;
for(int i=;i<=;i++){
f[i]=f[i-];
f[i][i]++;
for(it=f[i-].begin();it!=f[i-].end();it++){
f[i][lcm(it->first,i)]+=it->second;
}
}
for(scanf("%d",&Cas),cas=;cas<=Cas;cas++){
scanf("%d%I64d",&n,&m);printf("Case #%d: ",cas);
ans=;
for(it=f[n].begin();it!=f[n].end();it++){
if(it->first>=m) ans+=it->second;
}
printf("%I64d\n",ans);
}
return ;
}

hdu4028 The time of a day[map优化dp]的更多相关文章

  1. Codeforces 977F - Consecutive Subsequence - [map优化DP]

    题目链接:http://codeforces.com/problemset/problem/977/F 题意: 给定一个长度为 $n$ 的整数序列 $a[1 \sim n]$,要求你找到一个它最长的一 ...

  2. Consecutive Subsequence CodeForces - 977F (map优化DP)·

    You are given an integer array of length nn. You have to choose some subsequence of this array of ma ...

  3. CodeForces - 512B Fox And Jumping[map优化dp]

    B. Fox And Jumping time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. BZOJ 3357 [Usaco2004]等差数列:map优化dp

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3357 题意: 给你n个数a[i],让你找出一个最长的是等差数列的子序列. 题解: 表示状态 ...

  5. 【java】itoo项目实战之大数据查询之使用 new map 优化hibernate之级联查询

    在我的上一篇博客<[java]itoo项目实战之hibernate 懒载入优化性能>中,我曾提到过学生数据有2万条,查询数据十分的慢,这是让人非常受不了的事情.看着页面进度条一直转着圈圈, ...

  6. 单调队列优化DP,多重背包

    单调队列优化DP:http://www.cnblogs.com/ka200812/archive/2012/07/11/2585950.html 单调队列优化多重背包:http://blog.csdn ...

  7. 优化DP的奇淫技巧

    DP是搞OI不可不学的算法.一些丧心病狂的出题人不满足于裸的DP,一定要加上优化才能A掉. 故下面记录一些优化DP的奇淫技巧. OJ 1326 裸的状态方程很好推. f[i]=max(f[j]+sum ...

  8. BZOJ 1010: 玩具装箱toy (斜率优化dp)

    Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1... ...

  9. hdu 2829 Lawrence(四边形不等式优化dp)

    T. E. Lawrence was a controversial figure during World War I. He was a British officer who served in ...

随机推荐

  1. TCP/IP状态详解[转]

    TCP正常建立和关闭的状态变化     TCP连接的建立可以简单的称为三次握手,而连接的中止则可以叫做 四次握手.   建立连接   在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建 ...

  2. iOS彩票项目--第二天,自定义蒙版、封装活动菜单、自定义pop菜单

    一.自定义蒙版--封装控件,先想好外界怎么来调用,根据外界调用的方法,然后进入内部实现 在外部,调用蒙版的方法--[ChaosCover show]; [ChaosCover hide]; 内部实现 ...

  3. 微信分享SDK

    网址:http://www.8ru.org/weixin-js-sdk.html 下载demo:http://demo.open.weixin.qq.com/jssdk

  4. CMM已经落伍了,敏捷才是王道

    首先强调一下,敏捷和有没有文档一点关系都没有.我只是对于CMM的那些文档感觉有些浪费. 看看那些文档,看看那些流程.想想那些伟大的软件作品,哪个是用CMM开发出来的? 作为测试工程师,程序员的你在CM ...

  5. 第二百九十一节,RabbitMQ多设备消息队列-安装与简介

    RabbitMQ多设备消息队列-安装与简介 RabbitMQ简介 解释RabbitMQ,就不得不提到AMQP(Advanced Message Queuing Protocol)协议. AMQP协议是 ...

  6. MVC下载远程文件流(WebClient)

    public ActionResult DownLoad_File() { return File(ScLiu(PathUrl), "application/octet-stream&quo ...

  7. 【Java面试题】22 JAVA语言如何进行异常处理,关键字:throws,throw,try,catch,finally分别代表什么意义?在try块中可以抛出异常吗?

    throws是获取异常throw是抛出异常try是将会发生异常的语句括起来,从而进行异常的处理,catch是如果有异常就会执行他里面的语句,而finally不论是否有异常都会进行执行的语句. thro ...

  8. ulimit设置句柄数

    这几天在做一个性能测试,写了一个模拟发送http的程序.模拟100并发的情况下,随机发http get的请求.放到服务器上运行一段时间抛出Too many open files的异常. 这几天在做一个 ...

  9. liunx下误删除/var目录下的empty文件,导致ssh连接不上

    清理Liunx上不用的文件,导致误删 /var/下的empty文件,因为用的是ftp删的,所以可能有隐藏文件没有看到,导致其他同事都登录不上去 解决方法: 1.在/var文件夹下,重新建立empty文 ...

  10. 如何使用CodeSmith批量生成代码(原创系列教程)

    在上一篇我们已经用PowerDesigner创建好了需要的测试数据库,下面就可以开始用它完成批量代码生成的工作啦. 下面我会一步步的解释如何用CodeSmith实现预期的结果的,事先声明一下,在此只做 ...