0078-calculate the maximum factor

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.