#include <stdio.h>
int N, K, Fact=1, Zero, Ans1=1, Ans2;
int Table[10][4]={{},{0,1,1,1},{0,2,4,8},{0,3,9,7},{0,4,6,4},{0,5,5,5},{0,6,6,6},{0,7,9,3},{0,8,4,2},{0,9,1,9}};
int main(void) {
int i;
scanf("%d %d",&N,&K);
if(K)
for(i=1 ; i<=N ; i++) {
Fact*=i;
while(!(Fact%10)) Fact/=10, Zero++;
Fact%=10;
if(Ans2>K*Zero) Ans2=K*Zero, Ans1=Table[Fact][K];
else if(Ans2==K*Zero) {
Ans1+=Table[Fact][K];
if(Ans1==10) Ans1=1, Ans2++;
Ans1%=10;
}
}
else {
Ans1=N+1;
while(!(Ans1%10)) Ans1/=10;
Ans1%=10;
}
printf("%d",Ans1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1084 KB |
Output is correct - answer is '4' |
2 |
Correct |
0 ms |
1084 KB |
Output is correct - answer is '2' |
3 |
Correct |
0 ms |
1084 KB |
Output is correct - answer is '2' |
4 |
Correct |
0 ms |
1084 KB |
Output is correct - answer is '2' |
5 |
Correct |
0 ms |
1084 KB |
Output is correct - answer is '2' |
6 |
Correct |
0 ms |
1084 KB |
Output is correct - answer is '4' |
7 |
Correct |
0 ms |
1084 KB |
Output is correct - answer is '6' |
8 |
Correct |
0 ms |
1084 KB |
Output is correct - answer is '1' |
9 |
Correct |
0 ms |
1084 KB |
Output is correct - answer is '2' |
10 |
Correct |
0 ms |
1084 KB |
Output is correct - answer is '6' |
11 |
Correct |
0 ms |
1084 KB |
Output is correct - answer is '4' |
12 |
Incorrect |
0 ms |
1084 KB |
Output isn't correct - expected '5', found '1' |
13 |
Halted |
0 ms |
0 KB |
- |