Advertisement
Guest User

Vaishnav and Factorials

a guest
Sep 19th, 2014
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. //Bismillahir Rahmanir Rahim
  2. /******Harun Or Rashid******/
  3. /***********Template Starts Here***********/
  4. #include<iostream>
  5. #include<cstdio>
  6. #include<cstring>
  7. #include<cmath>
  8. #include<cctype>
  9. #include<cstdlib>
  10. #include<cassert>
  11. #include<string>
  12. #include<vector>
  13. #include<set>
  14. #include<stack>
  15. #include<queue>
  16. #include<map>
  17. #include<algorithm>
  18. using namespace std;
  19.  
  20. #define MEM(a,b) memset(a,b,sizeof(a))
  21. #define CLR(a) memset(a,0,sizeof(a))
  22. #define MAX(a,b) ((a)>(b)?(a):(b))
  23. #define MIN(a,b) ((a)>(b)?(b):(a))
  24. #define ABS(a) ((a)>0? (a):(-(a)))
  25. #define SQ(a) ((a)*(a))
  26. #define SZ(a) (int)a.size()
  27. #define FORN(i,n) for(i=1;i<=n;i++)
  28. #define FORAB(i,a,b) for(i=a;i<=b;i++)
  29. #define ALL(V) V.begin(),V.end()
  30. #define pb(a) push_back(a)
  31. #define pr(a) cout<<a<<endl
  32. #define SQR(a) ((a)*(a))
  33. #define pf printf
  34. #define sf scanf
  35. #define swap(a,b) (a ^= b, b ^= a, a ^= b)
  36. #define PI acos(-1)
  37. #define x first
  38. #define y second
  39. #define eps 1e-7
  40.  
  41. typedef int D;
  42. typedef long long int LLD;
  43. typedef unsigned long long int LLU;
  44. typedef vector<D> VI;
  45. typedef set<D> SI;
  46. typedef vector<D>::iterator Viti;
  47.  
  48. /***********Template Ends Here***********/
  49.  
  50. int main()
  51. {
  52.     int t,n,i,j,k,l,carry,fact[999999],cnt;
  53.     cin>>t;
  54.     while(t--)
  55.     {
  56.         cin>>n;
  57.         fact[0]=1;
  58.         l=1;
  59.         carry=0;
  60.         for(i=1; i<=n; i++)
  61.         {
  62.             for(j=0; j<l; j++)
  63.             {
  64.                 k=fact[j]*i+carry;
  65.                 fact[j]=k%10;
  66.                 carry=k/10;
  67.             }
  68.             while(carry)
  69.             {
  70.                 fact[l]=carry%10;
  71.                 carry/=10;
  72.                 l++;
  73.             }
  74.         }
  75.         cnt=0;
  76.         for(i=l-1; i>=0; i--) if(fact[i]==4 ||fact[i]==7) cnt++;
  77.         cout<<cnt<<endl;
  78.     }
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement