fork download
  1. #include <bits/stdc++.h>
  2.  
  3. long long inv = 301388891;
  4. long long mod = 1000000007;
  5. using namespace std;
  6. #define pb push_back
  7. #define mp make_pair
  8. #define fs first
  9. #define sc second
  10. const int INF = (1 << 30);
  11.  
  12. long long modpow(int a, long long b, long long m) {
  13. a %= m;
  14. long long r = 1;
  15. while (b > 0) {
  16. if (b & 1) r = (r * 1LL * a) % m;
  17. a = (a * 1LL * a) % m;
  18. b >>= 1;
  19. }
  20. return r;
  21. }
  22.  
  23. int A[10005];
  24.  
  25.  
  26.  
  27. int main() {
  28. ios_base::sync_with_stdio(false); cin.tie(0);
  29. A[1] = 4;
  30. A[2] = 7;
  31. int rn = 2, in = 3, pn = 0, sn = 3;
  32. for(int i = 1; i <= 9; ++i){
  33. for(int j = 1; j <= rn; ++j){
  34. A[in] = (4 * pow(10, i)) + A[pn + j];
  35. ++in;
  36. }
  37. for(int k = 1; k <= rn; ++k){
  38. A[in] = (7 * pow(10, i)) + A[pn + k];
  39. ++in;
  40. }
  41. rn = pow(2, i + 1);
  42. pn += pow(2 , i);
  43. }
  44. int n;
  45. cin>>n;
  46. // for(int i = 1; i <= 1000; ++i)
  47. // cout<<A[i]<<" ";
  48. int loc;
  49. for(int i = 1; i <= 10000; ++i){
  50. if(A[i] == n){
  51. loc = i;
  52. break;
  53. }
  54. }
  55. cout<<loc;
  56. return 0;
  57. }
Success #stdin #stdout 0s 3312KB
stdin
474744
stdout
83