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
 
题意:给你n个数,这n个数的大小为1~n,让你从中挑出一些数,使得这些数的最小公倍数大于等于m,求挑选的方案数。
思路:因为数的最小公倍数很大,所以不好dp,但是我们打表可以发现不同最小公倍数的总数量不是很大,所以我们用map<ll,ll>dp[50]来表示前i个数中挑选出的数的最小公倍数的值为j的方案数。

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef long double ldb;
#define inf 99999999
#define pi acos(-1.0)
ll gcd(ll a,ll b){
return (b>0)?gcd(b,a%b):a;
} ll cal(ll x,ll y)
{
ll num;
num=gcd(x,y);
return x*y/num; }
map<ll,ll>dp[50];
map<ll,ll>::iterator it; void init()
{
int i,j;
for(i=1;i<=40;i++)dp[i].clear();
dp[1][1]=1;
for(i=2;i<=40;i++){
for(it=dp[i-1].begin();it!=dp[i-1].end();it++){
dp[i][it->first]+=it->second;
dp[i][cal(it->first,i) ]+=it->second;
}
dp[i][i]+=1;
}
} int main()
{
int i,j,T,cas=0;;
ll n,m;
init();
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld",&n,&m);
ll sum=0;
for(it=dp[n].lower_bound(m);it!=dp[n].end();it++){
if(it->first>=m)
sum+=(it->second);
}
cas++;
printf("Case #%d: %lld\n",cas,sum);
}
return 0;
}

最新文章

  1. 【Win 10 应用开发】InkToolBar——涂鸦如此简单
  2. python2不同版本安装json模块
  3. C++11笔记&lt;一&gt;
  4. Blackfin DSP(八):1D DMA与音频处理模板
  5. StringUtils 的用法
  6. TListView的一些操作
  7. Effective Java 56 Adhere to generally accepted naming conventions
  8. 使用ContentProvider管理联系人------添加联系人
  9. @properties指针说明
  10. django基本命令备忘录
  11. c语言的第三次---单程循环结构
  12. Java基础 -- 复用类(组合和继承)
  13. PAT基础6-4
  14. 用分离、附加的方式实现sql server数据库的备份和还原
  15. iOS开发笔记-根据frame大小动态调整fontSize的自适应文本及圆形进度条控件的实现
  16. linux系统centOS7下搭建redis集群中ruby版本过低问题的解决方法
  17. 《大话处理器》Cache一致性协议之MESI (转)
  18. HACK字体安装
  19. java算法---五家共井
  20. 【leetcode】2-AddTwoNums

热门文章

  1. 搞定面试官:咱们从头到尾再说一次 Java 垃圾回收
  2. oracle rac与单实例DG切换
  3. MongoDB分片集群部署方案
  4. [Usaco2009 Feb]Revamping Trails 道路升级
  5. 翻译 - ASP.NET Core 基本知识 - 通用主机 (Generic Host)
  6. jmeter-命令行执行及测试报告导出
  7. Python+Selenium+Unittest实现PO模式web自动化框架(4)
  8. Promise用法
  9. axios用法
  10. (转)iOS工具--CocoaPods 安装使用总结