fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define endl "\n"
  4. #define F first
  5. #define S second
  6. #define loop(a,n) for(int i=a; i<=n ; i++)
  7. #define TIME (1.0 * clock() / CLOCKS_PER_SEC)
  8. #define NAME ""
  9. using namespace std;
  10.  
  11. int q, n;
  12.  
  13. int op (string a, int b) {
  14. int res = 0;
  15. for (char d: a)
  16. res = (res * 10 + (d - '0')) % b;
  17. return res;
  18. }
  19.  
  20. void solve(int n){
  21. string s = "1";
  22. while (true) {
  23. if (op(s, n) == 0) {
  24. cout << s.size() << endl;
  25. return;
  26. }
  27. s += '1';
  28. }
  29. }
  30.  
  31. void nhap(){
  32. cin >> q;
  33. while(q--) {
  34. cin >> n;
  35. solve(n);
  36. }
  37. }
  38. int main(){
  39. ios_base::sync_with_stdio(0);
  40. cin.tie(0);cout.tie(0);
  41. nhap();
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty