Skip to content

Instantly share code, notes, and snippets.

@KT-Yeh
Created February 8, 2014 14:14
Show Gist options
  • Save KT-Yeh/8884373 to your computer and use it in GitHub Desktop.
Save KT-Yeh/8884373 to your computer and use it in GitHub Desktop.
#include <cstdio>
using namespace std;
int main()
{
int B, A, S;
while (scanf("%d%d%d", &B, &A, &S) != EOF){
int carry = 0, len = 0, x = A;
while (1){
int tmp = x * S + carry;
carry = tmp / B;
x = tmp % B;
len++;
if (carry == 0 && x == A) break;
}
printf("%d\n", len);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment