Guest User

Untitled

a guest
Dec 18th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define S(a) scanf("%d",&a)
  6. typedef long long ll;
  7.  
  8. int main() {
  9.  
  10. {
  11. int a, b, c;
  12. S(a), S(b), S(c);
  13. // check if number a is divisible by b
  14. if (a % b == 0) {
  15. // if required digit is 0 the print 1 because 4/ 2 = 2.0
  16. if (c == 0) {
  17. printf("1\n");
  18. } else
  19.  
  20. printf("-1\n");
  21. return 0;
  22. }
  23.  
  24. // map to check repeated remainder
  25. unordered_map<int, bool> map;
  26.  
  27. // simulate the division process
  28. int i = 1;
  29. bool rep =0;
  30. for (ll r = a % b; r; r %= b) {
  31.  
  32. // meet a known remainder
  33. // so we reach the end of the repeating part
  34. if (map.find(r) != map.end()) {
  35. rep = 1;
  36. break;
  37. }
  38.  
  39. // the remainder is first seen
  40. // remember it
  41. map[r] = 1;
  42.  
  43. r *= 10;
  44. //found digit break
  45. if ((r / b) == c) {
  46. printf("%d\n", i);
  47. return 0;
  48. }
  49. i++;
  50. }
  51. if (!rep &&c == 0) {
  52. printf("%d\n", i);
  53. } else
  54. printf("-1\n");
  55. }
  56.  
  57. return 0;
  58. }
Add Comment
Please, Sign In to add comment