Question
| Maximum factor |
| Difficulty level: A; running time limit: 1000 ms; running space limit: KB; code length limit: B |
| Question description |
Input a positive integer n (n <1 000 000) on the keyboard, and output the maximum factor less than N. |
| Input |
| Only one positive integer n |
| Output |
| A positive integer that represents the maximum factor less than N |
| Input example |
| 100 |
| Output example |
| 50 |
Analysis
This question is very easy. This results in only one line of core code. As long as you understand the definition of a factor, that is, the nature, it is really easy.
Code
# Include <bits/stdc ++. h> using namespace STD; int N, ans; int main () {scanf ("% d", & N); For (INT I = 1; I <= (n/2); I ++)/* to n Limit 2, because the maximum positive integer factor of a positive integer is n Limit 2. */If (! (N % I) ans = I; // if I can be divisible by N, it indicates that it is a factor of N. Printf ("% d", ANS); Return 0 ;}
0078-calculate the maximum factor