#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char a[200001], b[200001];
int x[200001], y[200001];
int main()
{
int i, kx, ky, k, kk, c=0, z, ans=0;
scanf("%s", a);
scanf("%s", b);
kx = strlen(a);
ky = strlen(b);
for(i=1;i<=kx;i++){
if(a[kx-i]=='3') x[i] = 3;
if(a[kx-i]=='5') x[i] = 5;
if(a[kx-i]=='8') x[i] = 8;
}
for(i=1;i<=ky;i++){
if(b[ky-i]=='3') y[i] = 3;
if(b[ky-i]=='5') y[i] = 5;
if(b[ky-i]=='8') y[i] = 8;
}
k = 0;
if(kx>8){
for(i=kx;i>kx-8;i--){
k*=10;
k+=x[i];
}
k%=19980305;
for(i=kx-8;i>=1;i--){
k*=10;
k+=x[i];
k%=19980305;
}
}
else{
for(i=kx;i>=1;i--){
k*=10;
k+=x[i];
}
}
kk = k;
while(1){
if(x[1]==3){
x[1] = 5;
kk = k+2;
}
else if(x[1]==5){
x[1] = 8;
kk = k+3;
}
else{
x[1] = 3;
for(i=2;i<=kx+1;i++){
if(i==kx+1){
kx++;
x[i] = 3;
break;
}
if(x[i]==3){
x[i] = 5;
break;
}
else if(x[i]==5){
x[i] = 8;
break;
}
else{
x[i] = 3;
}
}
kk = 0;
if(kx>8){
for(i=kx;i>kx-8;i--){
kk*=10;
kk+=x[i];
}
kk%=19980305;
for(i=kx-8;i>=1;i--){
kk*=10;
kk+=x[i];
kk%=19980305;
}
}
else{
for(i=kx;i>=1;i--){
kk*=10;
kk+=x[i];
}
}
}
z = 0;
for(i=1;i<=ky;i++){
if(x[i]!=y[i]){
z = 1;
break;
}
}
ans = (ans+(k*kk))%19980305;
if(z==0) break;
k = kk;
}
printf("%d", ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
2840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
2840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
2840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1000 ms |
0 KB |
Program timed out |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1000 ms |
0 KB |
Program timed out |
2 |
Halted |
0 ms |
0 KB |
- |