-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path10323.cpp
executable file
·101 lines (86 loc) · 1.45 KB
/
10323.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include <iomanip>
using namespace std ;
long long int factorial( long long int n )
{
if( n == 0 )
return 1 ;
else
return n * factorial( n - 1 ) ;
}
int main()
{
int n = 0 ;
int i = 0 ;
while( cin >> n )
{
if( n < 0 )
{
if( n % 2 == 0 )
cout << "Underflow!" << endl ;
else
cout << "Overflow!" << endl ;
continue ;
}
else if( n > 13 )
cout << "Overflow!" << endl ;
else if( n < 8 )
cout << "Underflow!" << endl ;
else
cout << factorial( n ) << endl ;
}
return 0 ;
}
/* may be a correct but TLE version
#include <iostream>
#include <iomanip>
using namespace std ;
long long int factorial( int n, int &solved )
{
long long int temp = 0 ;
if( n == 0 )
{
return 1 ;
}
else
{
temp = n * factorial( n - 1, solved ) ;
if( solved == 0 )
{
if( temp > 62270208 * 100 )
solved = 1 ;
}
return temp ;
}
}
int main()
{
long long int ans = 0 ;
int solved = 0 ;
int n = 0 ;
int i = 0 ;
while( cin >> n )
{
if( n < 0 )
{
if( n % 2 == 0 )
cout << "Underflow!" << endl ;
else
cout << "Overflow!" << endl ;
continue ;
}
solved = 0 ;
ans = factorial( n, solved ) ;
if( solved == 0 )
{
if( ans < 10000 )
cout << "Underflow!" << endl ;
else
cout << ans << endl ;
}
else if( solved > 0 )
cout << "Overflow!" << endl ;
}
return 0 ;
}
*/