-
Notifications
You must be signed in to change notification settings - Fork 1
/
Factorials.cpp
53 lines (46 loc) · 943 Bytes
/
Factorials.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
ID: zdzapple
LANG: C++
TASK: fact4
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <climits>
#include <fstream>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
using namespace std;
const string input_file = "fact4.in";
const string out_file = "fact4.out";
ifstream fin;
ofstream fout;
void openfile() { fin.open(input_file.c_str()); fout.open(out_file.c_str()); }
void closefile() { fin.close(), fout.close(); }
int N;
int main()
{
openfile();
int i, j, k;
fin >> N;
int fac = 1;
for (i = 1; i <= N; ++i)
{
fac *= i;
while (fac % 10 == 0)
fac /= 10;
if (fac > 1000)
fac %= 1000;
}
fout << fac%10 << endl;
closefile();
}