Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <math.h>
- #include <set>
- #include <cstring>
- #include <stdio.h>
- #include <algorithm>
- using namespace std;
- void sum(vector <int> &a, vector <int> b);
- unsigned long long int pow3(int n)
- {
- if (n == 0)
- return 1;
- unsigned long long int a = pow3(n/2);
- if (n&1)
- return 3*a*a;
- return a*a;
- }
- void print(vector <int> a)
- {
- bool bol = 1;
- for (int i = 0; i != 60; i++)
- {
- if (a[i] != 0)
- bol = 0;
- if (!bol)
- printf("%d", a[i]);
- }
- return ;
- }
- unsigned long long int poww(int n)
- {
- if (n <= 0)
- return 0;
- return pow3(n-1)*2;
- }
- void multiply(vector <int> &a)
- {
- int p, peren = 0, i;
- for (i = 59; i >= 0; i--)
- {
- p = (a[i]*2 + peren)/10;
- a[i] = (a[i]*2+peren)%10;
- peren = p;
- }
- return ;
- }
- vector <int> all(int n)
- {
- vector <int> a;
- for (int i = 0; i != 59; i++)
- a.push_back(0);
- a.push_back(1);
- for (int i = 0; i != n; i++)
- {
- multiply(a);
- }
- return a;
- }
- vector <int> how(char *c, int len)
- {
- vector <int> a;
- for (int i = 0; i != 60; i++)
- a.push_back(0);
- if (len == 0)
- {
- a[59] = 1;
- return a;
- }
- if (c[0] < '3')
- return a;
- if (c[0] >= '3')
- {
- if (c[0] == '3')
- sum(a, how(c+1, len-1));
- else
- sum(a, all(len-1));
- }
- if (c[0] >= '7')
- {
- if (c[0] == '7')
- sum(a, how(c+1, len-1));
- else
- sum(a, all(len-1));
- }
- return a;
- }
- void sum(vector <int> &a, vector <int> b)
- {
- int i, peren = 0, p;
- for (i = 59; i >= 0; i--)
- {
- p = (a[i] + b[i] + peren)/10;
- a[i] = (a[i] + b[i] + peren) % 10;
- peren = p;
- }
- return ;
- }
- int main()
- {
- char c[61];
- fgets(c, 61, stdin);
- int len = strlen(c)-1;
- vector <int> a;
- for (int i = 0; i != 59; i++)
- a.push_back(0);
- a.push_back(1);
- for (int i = 0; i != len; i++)
- {
- multiply(a);
- }
- int p, peren = 2;
- for (int i = 59; i >= 0 && peren; i--)
- {
- p = (a[i] - peren) < 0 ? 1 : 0;
- a[i] = (a[i] - peren) < 0 ? 10 +(a[i] - peren) : a[i] - peren;
- peren = p;
- }
- if (len == 0)
- {
- cout << "0";
- return 0;
- }
- if (len == 1)
- {
- int v = 0;
- if (c[0] >= '3')
- v++;
- if (c[0] >= '7')
- v++;
- printf("%d", v);
- return 0;
- }
- if (c[0] >= '3')
- {
- if (c[0] == '3')
- sum(a, how(c+1, len-1));
- else
- sum(a, all(len-1));
- }
- if (c[0] >= '7')
- {
- if (c[0] == '7')
- sum(a, how(c+1, len-1));
- else
- sum(a, all(len-1));
- }
- print(a);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement