Input A B M

C = 1e9

The equation of p2 winning is (Na * C + Nb) % M == 0, that's (Na * (C % M) + Nb % M) % M == 0

Further, p1 controls M1 = (Na * (C % M)) % M, p2 controls M2 = Nb % M

If B >= M - 1,  P1 has no chances to win, because P2 can always pick a number makes (M2 + M1) % M == 0

If A == B == 0, the same result.

So, when B < M-1, then 1 <= M1 <= M-B-1 will make p1 wins.

#include <stdio.h>

int main() {
int A, B, M, i, m, C = 1e9, d;
scanf("%d %d %d", &A, &B, &M);

int min = ( A < M ? A : M-1 );
if( B >= M-1 || ( A == 0 && B == 0 ) ) {
printf("2\n");
return 0;
}
C = C % M; // C = 1e9 % M
m = 0;
d = M-B;
for( i=1;i<=min;i++ ) {
m += C; // m is i * 1e9 % M
if( m > M ) m -= M;
if( m == 0 ) break; // because m starts from 0, if 0 again, means no chance.
if( 1 <= m && m < d ) {
printf("1 %.9d\n", i);
return 0;
}
}

printf("2\n");

return 0;
}


 

相关文章:

  • 2021-10-24
  • 2021-06-26
  • 2021-12-11
猜你喜欢
  • 2021-06-24
  • 2021-06-28
  • 2021-05-28
  • 2021-09-29
  • 2022-12-23
  • 2021-09-13
  • 2021-04-02
相关资源
相似解决方案