fork(1) download
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4.  
  5. using namespace std;
  6.  
  7. bool check25(int b)
  8. {
  9. while(b%2==0)
  10. b/=2;
  11. while(b%5==0)
  12. b/=5;
  13. return b==1;
  14. }
  15. int main()
  16. {
  17. int a,b;
  18. while(cin>>a>>b,b!=0)
  19. {
  20. int g=__gcd(a,b);
  21. a/=g; b/=g;
  22. if(check25(b))
  23. {
  24. cout<<1<<endl;
  25. continue;
  26. }
  27. long long nine=9;
  28. for(int i=1;;i++)
  29. {
  30. if(nine%b==0)
  31. {
  32. cout<<i<<endl;
  33. break;
  34. }
  35. nine=nine%b*10+9;
  36. }
  37. }
  38. }
  39.  
Success #stdin #stdout 0s 3344KB
stdin
1 7
2 3
1 1
2 0
stdout
6
1
1