Skip to content

Instantly share code, notes, and snippets.

@kngwyu
Created January 10, 2016 15:02
Show Gist options
  • Save kngwyu/b18cb2e0ba43ed643e9c to your computer and use it in GitHub Desktop.
Save kngwyu/b18cb2e0ba43ed643e9c to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0; i<(int)(n);i++)
ll n, temp;
int main(){
cin >> n;
vector<int> d[n+1];
temp = 1;
for(int i = 1; i <= n;i++){
temp *= i;
ll a = temp;
bool er = false;
for(int j=0; a>=0;j++, a/=10){
int key = a%10;
if(j == 0 && key == 0) er = true;
if(key!=0) er = false;
if(er==false)d[i].push_back(key);
if(d[i].size()==9) break;
}
temp = 0;
for(int j=1,k=0; k < d[i].size(); j*=10, k++){
temp += j*d[i][k];
}
}
bool p = false;
int k = d[n].size()-1;
for(int i = k; i>=0;i--){
if(i==k && d[n][i] ==0) p = true;
if(d[n][i] != 0) p = false;
if(p==false)cout << d[n][i];
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment