Created
March 3, 2015 05:53
-
-
Save henrybear327/098321c7709f52703aea to your computer and use it in GitHub Desktop.
w1c.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int data[100000 + 1]; | |
int main() | |
{ | |
int p, q; | |
while(scanf("%d %d", &p, &q) != EOF && q) { | |
memset(data, -1, sizeof(data)); | |
if(p == q) | |
printf("1\n"); | |
else { | |
int count = 1; | |
int remainder = p * 10 % q; | |
while(data[remainder] == -1) { | |
data[remainder] = count; | |
count++; | |
p = remainder; | |
remainder = p * 10 % q; | |
} | |
printf("%d\n", count - data[remainder]); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment