HDU 4028 the time of a day (number theory, discrete DP)

Source: Internet
Author: User
The time of a day

Time Limit: 2000/1000 MS (Java/others) memory limit: 65768/65768 K (Java/Others)
Total submission (s): 742 accepted submission (s): 327

Problem descriptionthere are no days and nights on Byte Island, so the residents here can hardly determine the length of a single day. fortunately, they have got Ted 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.

 

Inputthere 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)

 

Outputfor each test case, output a single integer denoting the number of ways.

 

Sample input3 5 5 10 1 10 128

 

Sample outputcase #1: 22case #2: 1023 case #3: 586

 

Sourcethe 36th ACM/ICPC Asia Regional Shanghai site -- online contest

 

Recommendlcy discrete DP. Is to find any number of LCM selected from 1-n.
# Include <stdio. h> # Include <Algorithm> # Include < String . H> # Include <Iostream> # Include <Map> Using   Namespace  STD; Map < Long   Long ,Long   Long > DP [ 45  ];  Long   Long Gcd ( Long   Long A, Long   Long  B ){  If (B = 0 ) Return  A;  Return Gcd (B, A % B );}  Long   Long LCM ( Long   Long A, Long   Long  B ){  Return A * B/ Gcd (a, B );}  Int  Main () {DP [  1 ] [ 1 ] = 1 ; Map < Long   Long , Long   Long > : Iterator it;  For ( Int I = 2 ; I <= 40 ; I ++ ) {DP [I] = DP [I- 1  ]; DP [I] [I] ++ ; For (It = DP [I- 1 ]. Begin (); it! = DP [I- 1 ]. End (); It ++ ) {DP [I] [lcm (it -> First, I)] + = it-> Second ;}}  Int  T;  Int Icase = 0  ; Scanf (  "  % D  " ,& T ); Int  N;  Long   Long  M;  While (T -- ) {Icase ++ ; Scanf (  "  % D % i64d  " , & N ,& M );  Long   Long Ans = 0 ;  For (It = DP [N]. Begin (); it! = DP [N]. End (); It ++ )  If (It-> first> = M) ans + = It-> Second; printf (  "  Case # % d: % i64d \ n  "  , Icase, ANS );}  Return   0  ;} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.