SMALLM - Smallest Number (medium)
60 is divisible by 2, 3, 4 and 5. No smaller number than 60 has this property.
Input
On the first line, you will be given two integers T (the number of test cases), and M (an integer). Each of the next T lines contains an integer N.
Output
For each test case, output on one line, the smallest number that is divisible by all integers from 1 to N (inclusive). As the answer may be a big number, output it modulo M.
Example
Input: 1 1000000007 5 Output: 60
Constraints
T <= 10^5
10^8 <= M <= 2×10^9, a prime number
0 < N < 10^8
Information
There's one easy input file, and several harder ones. Time limit allows unoptimized code with fast languages to get AC ; for slower languages it may be hard. Good luck and have fun ;-)
Edit(2017-02-11) : New time limit (after compiler changes).
hide comments
[Lakshman]:
2015-01-29 08:28:22
I am curious to know how this problem can be done in in less than 4 mb. Is there any formula? or some different method for this, I have reduced this problem to O(sqrt(sqrt(n))) But still ...But still can't get any idea of any algorithm that takes less than 50 MB. @Francky if you find this comment spoiler you can delete it or you can hide(as you wish).
|
|
sourav:
2015-01-26 18:54:29
can we take an array of long long of size 5*10^7..bcoz i m getting sigkill re
|
|
[Lakshman]:
2015-01-26 03:36:04
@Francky Can please tell me if I am getting TLE in all input files or only in hard one. Thanks.
|
|
ISHANI:
2015-01-25 19:27:51
My complexity is O(n)+t*O(1).still getting TLE.Francky,is it enough or not?
|
|
[Lakshman]:
2015-01-25 15:50:27
My complexity in worst case is T*2400*log(n) + some pre-computation is it no enough to pass the time limit. |
|
Francky:
2015-01-24 20:36:47
Congrats to Mitch as the first solver.
|
|
Francky:
2015-01-24 18:46:19
I tried an edition possible with N<10^18 (using a simplification by some primorial), but in fine it was too artificial, so I propose a 10^8 edition, with fixed modulo given in input.
|
Added by: | Francky |
Date: | 2015-01-24 |
Time limit: | 0.5s-2s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 JS-MONKEY |
Resource: | SMALL |