FactorialTower
SRM 283 · 2006-01-19 · by gevak
SRM 283 · 2006-01-19 · by gevak · Math, Simple Search, Iteration
Problem Statement
Problem Statement
Note: this problem statement contains an image that may not display properly if viewed outside the applet.
Given an
Notes
- The expression is calculated from top to bottom. See example 5.
- "x mod y" means the remainder of x divided by y.
- Assume 0! = 1.
Constraints
- a will contain between 1 and 50 elements, inclusive.
- Each element of a will be between 0 and 2147483647, inclusive.
- m will be between 1 and 40000, inclusive.
Examples
0)
{2,2,2,2}
10
Returns: 6
Last digit of 65536.
1)
{3,8}
100
Returns: 76
(3!8!) mod 100 = 76.
2)
{775,967,1,1,1}
39877
Returns: 4832
3)
{0}
40000
Returns: 1
Remember that 0! is 1.
4)
{5,4,123456789,987654321,687955994,1162330089,195458992,1687386387,
1092101949,1086091397,902287014,341660341,1600834655,131565486,1494304912,
384585199,1883009662,916903507,1895924341,397197724,1883021244,1616061080,
1437763283,621297237,1883141487,282508826,285957625,1249530903,1484124572,
1822993209,1668351723,174237628,1589170712,992959839,1281777023,1158939002,
1488964134,1806511164,1519656093,159671689,542573000,1571768398,1203500608,
1053387535,793607740,1535801392,1798307613,552983945,901802936,1023595016}
40000
Returns: 0
12)
{2,3,2}
36864
Returns: 4096
The expression is calculated from top to bottom. (2! to the power of (3!2!)) mod 36864 = 4096.
Submissions are judged against all 97 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class FactorialTower with a public method int exprValue(vector<int> a, int m) · 97 test cases · 2 s / 256 MB per case