-
Notifications
You must be signed in to change notification settings - Fork 0
/
Highest Divisor.cpp
75 lines (46 loc) · 1.03 KB
/
Highest Divisor.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
Task: You are given an integer N. Find the largest integer between 1 and 10 (inclusive) which divides N
.
Input
The first and only line of the input contains a single integer N
.
Output
Print a single line containing one integer ― the largest divisor of N
between 1 and 10
.
Constraints
2≤N≤1,000
Subtasks
Subtask #1 (100 points): original constraints
Example Input 1
24
Example Output 1
8
Explanation
The divisors of 24
are 1,2,3,4,6,8,12,24, out of which 1,2,3,4,6,8 are in the range [1,10]. Therefore, the answer is max(1,2,3,4,6,8)=8
.
Example Input 2
91
Example Output 2
7
Explanation
The divisors of 91
are 1,7,13,91, out of which only 1 and 7 are in the range [1,10]. Therefore, the answer is max(1,7)=7
Solution:
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
long long n,i;
cin>>n;
for(i=10;i>=1;i--){
if(n%i==0){
break;
}
}
cout<<i<<endl;
return 0;
}