fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define MOD 1000000007
  4. #define LL long long
  5. #define out(x) cout << #x << " : " << x << "\n";
  6.  
  7. int firstKdigit(int p, int k) {
  8. double lg = p * log10(2) / log10(10);
  9. double f = lg - floor(lg) + k - 1;
  10. return pow(10, f);
  11. }
  12.  
  13. int main() {
  14. int n; cin >> n;
  15. int k = log10(n) + 1;
  16. bool ok = false;
  17. for(int i = 0;i <= 100000000;i++) {
  18. int fk = firstKdigit(i, k);
  19. //cout << fk << " ";
  20. if(fk == n) {
  21. cout << i << "\n";
  22. ok = true;
  23. break;
  24. }
  25. }
  26. if(!ok) cout << -1;
  27. return 0;
  28. }
  29.  
  30.  
Success #stdin #stdout 0s 3100KB
stdin
82
stdout
209