ProductTriplet
Member SRM 458 · 2009-12-03 · by rng_58
Member SRM 458 · 2009-12-03 · by rng_58 · Brute Force, Math
Problem Statement
Problem Statement
You are given six integers, minx, maxx, miny, maxy, minz and maxz. Return the number of triplets of integers (x,y,z) that satisfy the following three conditions:
- x is between minx and maxx, inclusive.
- y is between miny and maxy, inclusive.
- z is between minz and maxz, inclusive.
- x * y = z
Constraints
- maxx will be between 1 and 1,000,000,000, inclusive.
- maxy will be between 1 and 1,000,000,000, inclusive.
- maxz will be between 1 and 1,000,000,000, inclusive.
- minx will be between 1 and maxx, inclusive.
- miny will be between 1 and maxy, inclusive.
- minz will be between 1 and maxz, inclusive.
Examples
0)
2 2 3 3 6 6 Returns: 1
2 * 3 = 6.
1)
2 2 3 3 7 7 Returns: 0
2 * 3 is not 7.
2)
6 8 4 5 27 35 Returns: 4
(x,y,z) = (6,5,30), (7,4,28), (7,5,35) and (8,4,32) satisfy all conditions.
3)
1 458 1 458 1 458 Returns: 2877
4)
8176 184561 1348 43168 45814517 957843164 Returns: 2365846085
Submissions are judged against all 44 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class ProductTriplet with a public method long long countTriplets(int minx, int maxx, int miny, int maxy, int minz, int maxz) · 44 test cases · 2 s / 256 MB per case