CountingSeries
SRM 523 · 2011-05-25 · by vexorian
Problem Statement
Notes
- The ^ operator in this statement denotes the exponentiation operation. For example, 3^0 = 1 and 2^4 = 2*2*2*2 = 16.
Constraints
- a, b, c and upperBound will each be between 1 and 1000000000000 (10^12), inclusive.
- d will be between 1 and 100000 (10^5), inclusive.
1 1 1 2 1000 Returns: 1000
The arithmetic progression is: 1, 2, 3, 4, ... . The geometric progression is: 1, 2, 4, 8, 16, ... . Each positive integer is contained in at least one of the progressions.
3 3 1 2 1000 Returns: 343
This time, the arithmetic progression is: 3, 6, 9, 12, ... . The geometric progression is still: 1, 2, 4, 8, 16, .... There are 333 multiples of 3 between 1 and 1000, inclusive, and there are 10 powers of 2, 512 being the highest. As these two progressions do not have any common elements, the total result is 343.
40 77 40 100000 40 Returns: 1
452 24 4 5 600 Returns: 10
The 10 numbers are: 4, 20, 100, 452, 476, 500, 524, 548, 572 and 596.
1000000000000 1000000000000 1000000000000 100000 1000000000000 Returns: 1
Submissions are judged against all 537 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class CountingSeries with a public method long long countThem(long long a, long long b, long long c, long long d, long long upperBound) · 537 test cases · 2 s / 256 MB per case