Last three digits of (3 + √5)^n
Time limit5sMemory limit512 MB
Compute the last three digits before the decimal point of (3 + sqrt(5))^n for n up to two billion.
- Level
Medium6 of 10
- Topics
- Math, Number theory, Dynamic programming
- Solved
- No attempts yet
Problem
Given a positive integer , find the last three digits before the decimal point of .
For example, when , , so the answer is 935. When , , so the answer is 027.
Input
The first line holds the number of test cases .
Each of the next lines holds one positive integer .
Output
For each test case print one line in this format.
Case #X: Y
is the test case number starting from 1, and is the last three digits before the decimal point of . If the integer part has fewer than three digits, pad it with leading zeros so that the output always has exactly three digits.