码迷,mamicode.com
首页 > 其他好文 > 详细

hdu4028The time of a day

时间:2015-04-14 21:36:18      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

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


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
The 36th ACM/ICPC Asia Regional Shanghai Site —— Online Contest

[1,n]中挑出任意数,它们的最小公倍数不小m

有多少种挑选方法
 
dp[i][j]:[1,i]中挑出任意数,它们的最小公倍数不小j的方法数


dp[i][lcm(i,j)]+=dp[i-1][j]

注意,由于只有a时最小公倍数也算作是a,所以,dp[i][i]++

#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
	return a/gcd(a,b)*b;
}
map<ll,ll>dp[50];
int main()
{
	dp[1][1]=1;
	for(ll i=2;i<=40;i++)
	{
		dp[i]=dp[i-1];
		dp[i][i]++;
		for(map<ll,ll>::iterator it=dp[i-1].begin();it!=dp[i-1].end();it++)
			dp[i][lcm(it->first,i)]+=it->second;
	}
	int T;
	cin>>T;
	for(int cs=1;cs<=T;cs++)
	{
		int n;
		ll m;
		cin>>n>>m;
		ll ans=0;
		for(map<ll,ll>::iterator it=dp[n].lower_bound(m);it!=dp[n].end();it++)
			ans+=it->second;
		cout<<"Case #"<<cs<<": "<<ans<<endl;
	}
}


hdu4028The time of a day

标签:

原文地址:http://blog.csdn.net/stl112514/article/details/45047473

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!