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. [从jQuery看JavaScript]-注释(comments)

    jQuery片段: /*! * jQuery JavaScript Library v1.3.2 * http://jquery.com/ * * Copyright (c) 2009 John Re ...

  2. 关于Cocos2d-x的专属数据类型

    1.Size类定义的实例是一个有width和height属性的类 Size s = Size(44,52); 其中 s.width=44 s.height=52 2.Vec2是一个带有两个变量的(常量 ...

  3. 【转】C# 调用WebService的方法

    很少用C#动态的去调用Web Service,一般都是通过添加引用的方式,这样的话是自动成了代理,那么动态代理调用就是我们通过代码去调用这个WSDL,然后自己去生成客户端代理.更多的内容可以看下面的两 ...

  4. 使用ffmepg的lib库调试,debug版本下调试无问题,但release版本会出现跑飞的现象

    如题(“使用ffmepg的lib库调试,debug版本下调试无问题,但release版本会出现跑飞的现象”). 今天使用ffmpeg进行宿放和颜色格式转换,很简单的代码,却折腾了我一天,这里说来就气啊 ...

  5. linux -- 修改文件

    vi编辑器有三种模式:命令模式,编辑模式,末行模式 打开vi后首先是命令模式,用i,o,a等进入编辑模式, 按esc退出编辑模式,回到命令模式. 在命令模式下输入:wq表示保存退出,:wq!强制保存退 ...

  6. Java处理图片时编译不通过

    Java中处理图片时,MyEclipse需要导入以下包: import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.image.codec.j ...

  7. (转载)UTF-8和GBK的编码方式的部分知识:重要

    GBK的文字编码是双字节来表示的,即不论中.英文字符均使用双字节来表示,只不过为区分中文,将其最高位都定成1. 至于UTF-8编码则是用以解决国际上字符的一种多字节编码,它对英文使用8位(即一个字节) ...

  8. 初次使用ets

    一.new(Name, Options) -> tid() | atom(),创建ets表. Options = [Option], 目测常用的属性, {keypos, Pos}:指定key的位 ...

  9. u3d change terrain textrue&height

    using UnityEngine; using System.Collections; public class terrainTest : MonoBehaviour { ; private Te ...

  10. SharePoint 沙盒无法启动新的解决方案服务的SPUserCodeV4

    开发部署时报错: 错误原因:没有启动该服务: 解决方式:打开管理中心—应用程序管理—服务应用程序--管理服务器上的服务,启动该服务即可.