Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- /// 25 -> 15511210043330985984000000
- int nrcifre(int n)
- {
- int nr=0;
- while(n)
- ++nr,n/=10;
- return nr;
- }
- int main()
- {
- int n,k;
- ifstream f("kfact.in");
- f>>n>>k;
- f.close();
- ofstream g("kfact.out");
- if(n==0)
- {
- g<<-1;
- return 0;
- }
- unsigned long long int MOD=10000000000,fact=1;
- for(int i=1;i<=n;++i)
- {
- /// g<<fact<<'*'<<i<<" = ";
- fact=fact*i;
- /// g<<fact<<endl;
- while(fact%10==0) /// Renunt la zerouri
- fact/=10;
- fact%=MOD;
- }
- int nrcif=nrcifre(fact);
- if(nrcif<k)
- {
- g<<-1;
- return 0;
- }
- for(int i=1;i<k;++i)
- fact/=10;
- g<<fact%10;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement