Code: Select all
AC
Moderator: Board moderators
Code: Select all
AC
For the following inputHowever, you should NOT print any leading zero.
Code: Select all
100 100 10 2
Code: Select all
0
Code: Select all
16
0 1 14 1
0 1 24 1
0 1 74 1
25 67 3 1
98 25 1000000000 1
0 1 9842 2
34 88 224242 2
100 100 10 2
56 24 83943 3
89 14 983821 3
1 100 1000000000 4
45 64 999999999 4
0 0 100000 4
100 90 0 4
41 67 1 3
55 89 2 4
Code: Select all
7
8
7
9
3
21
92
0
664
54
8126
1269
0
100
67
144
Thanks for sharing your thoughts.brianfry713 wrote:a single zero isn't considered a leading zero because it's not "leading" anything. Your interpretation of that line was incorrect, not the problem description.
Code: Select all
16
0 1 14 1
0 1 24 1
0 1 74 1
25 67 3 1
98 25 1000000000 1
0 1 9842 2
34 88 224242 2
100 100 10 2
56 24 83943 3
89 14 983821 3
1 100 1000000000 4
45 64 999999999 4
0 0 100000 4
100 90 0 4
41 67 1 3
55 89 2 4
Code: Select all
#include <bits/stdc++.h>
using namespace std;
int fib[15010];
int main() {
int a, b, c, i, m, t, x;
unsigned long long n;
//freopen("input.txt", "r", stdin);
scanf("%d", &t);
while (t--) {
scanf("%d %d %llu %d", &a, &b, &n, &m);
c = (pow(10, m));
fib[1] = a % c;
fib[2] = b % c;
if (m == 1)
x = 60;
else if (m == 2)
x = 300;
else if (m == 3)
x = 1500;
else if (m == 4)
x = 15000;
for (i = 3; i <= x; i++)
fib[i] = (fib[i - 1] + fib[i - 2]) % c;
n = (n + 1) % x;
printf("%d\n", fib[n]);
}
return 0;
}