Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define S(a) scanf("%d",&a)
- typedef long long ll;
- int main() {
- {
- int a, b, c;
- S(a), S(b), S(c);
- // check if number a is divisible by b
- if (a % b == 0) {
- // if required digit is 0 the print 1 because 4/ 2 = 2.0
- if (c == 0) {
- printf("1\n");
- } else
- printf("-1\n");
- return 0;
- }
- // map to check repeated remainder
- unordered_map<int, bool> map;
- // simulate the division process
- int i = 1;
- bool rep =0;
- for (ll r = a % b; r; r %= b) {
- // meet a known remainder
- // so we reach the end of the repeating part
- if (map.find(r) != map.end()) {
- rep = 1;
- break;
- }
- // the remainder is first seen
- // remember it
- map[r] = 1;
- r *= 10;
- //found digit break
- if ((r / b) == c) {
- printf("%d\n", i);
- return 0;
- }
- i++;
- }
- if (!rep &&c == 0) {
- printf("%d\n", i);
- } else
- printf("-1\n");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment