原題鏈接
(a-b)%c = (a%c - b%c)%c
#include#include char str[105]; int main(){ int c, len, a, i; while(scanf("%s", str), str[0] != '0'){ len = strlen(str); if(len == 1){ printf("0\n"); continue; } c = str[len - 1] - '0'; str[len - 1] = '\0'; if(len < 10){ sscanf(str, "%d", &a); a -= c * 5; printf("%d\n", a % 17 ? 0 : 1); continue; } //大數取余 for(i = a = 0; i != len - 1; ++i){ a = (a * 10 + str[i] - '0') % 17; } c = c * 5 % 17; printf("%d\n", (a - c) % 17 ? 0 : 1); } return 0; }