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. Hive Tunning(二)优化存储

    接着上一章我们讲的hive的连接策略,现在我们讲一下hive的数据存储. 下面是hive支持的数据存储格式,有我们常见的文本,JSON,XML,这里我们主要讲一下ORCFile. Built-in F ...

  2. iOS边练边学--通讯录练习之Segue使用,控制器的数据传递

    一.什么是segue Storyboard上每一根用来界面跳转的线,都是一个UIStoryboardSegue对象(简称Segue) 二.Segue的属性 每一个segue对象,都有三个属性 < ...

  3. DataGridView使用技巧四:删除行操作

    一.无条件的删除行 默认时,DataGridView是允许用户进行行的删除操作,选中要删除的行,按Delete键可以删除,该操作没有任何提示(只是删除界面显示的数据,不会真实删除数据库中的数据).如果 ...

  4. CodeIgniter(3.1.4)框架使用静态文件(js,css)

    调整目录结构: 可以在控制器中这样加载视图: * 加载url辅助类. views视图中可以这样引用静态文件: 则最终的静态文件url会生成这样:

  5. 说说$POST 、$HTTP_RAW_POST_DATA、php://input三者之间的区别

    $POST $_POST是我们最常用的获取POST数据的方式,它是以关联数组方式组织提交的数据,并对此进行编码处理,如urldecode,甚至编码转换,识别的数据类型是PHP默认识别的数据类型 app ...

  6. 将sqlServer上的数据库文件进行盘目的迁移

    在数据库客户端创建数据库时要改为.mdf文件,因为附加问价时附加的是.mdf文件: 在里选中相应的数据库 右键->任务-分离 在 剪切到相应的想放置的盘目. 例如迁移到E盘下: 在数据库-> ...

  7. laravel 视图与传参

    1:先建立好一个控制器HgjController,其中index方法 return  view('hgj'); 2: 建立视图 在resources/views/hgj.blad.php <ht ...

  8. JS三大经典变量命名法

    匈牙利命名法: 通过在变量名前面添加相应小写字母的符号标示作为前缀,标示出变量的作用域,类型等,前缀后面是一个或多个单词组合,单词描述了变量的用途,如i表示的是整数,s表示的是字符串.示例: var ...

  9. Spring事务:调用同一个类中的方法

    问题: 如果同一个类中有方法:methodA(); methodB().methodA()没有开启事务,methodB()开启了事务 且methodA()会调用methodB(). 那么,method ...

  10. IoC就是IoC,不是什么技术,与GoF一样,是一种 设计模式。

    IoC就是IoC,不是什么技术,与GoF一样,是一种 设计模式. Interface Driven Design接口驱动,接口驱动有很多好处,可以提供不同灵活的子类实现,增加代码稳定和健壮性等等,但是 ...