Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef unsigned long long ull;
- ull factorial(ull n);
- main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- ull n, i, fact[21], j;
- cin>>n;
- stack<ull>num_stack;
- //To store factorials upto 20 in the array.
- for(i=0; i<21; i++)
- {
- fact[i]=factorial(i+1);
- }
- for(j=19; j>=0; j--)
- {
- if(fact[j]<=n)
- {
- num_stack.push(j+1);
- n=n-fact[j];
- }
- }
- cout<<num_stack.top()<<' '<<n;
- }
- ull factorial(ull n)
- {//factorial(0)= 1
- if(n==0)
- return 1;
- else
- return n*factorial(n-1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement