HDU 4627 The unsolvable problem problem-solving experience

Source: Internet
Author: User

Original question:

Description

There is many unsolvable problem in the world. It could is about one or about zero. But this time it was about bigger number.
Given an integer n (2 <= n <= 10 9). We should find a pair of positive integerA, b so, a + b = N and [A, b] are as large as possible. [A, b] denote the least common multiplier of a, B.

Input

The first line contains integer T (1<= t<= 10000), denote the number of the the test cases.
For each test cases,the first line contains an integer n.

Output

For each test cases, print the maximum [a, b]In a line.

Sample Input

3234

Sample Output

123 Analysis: The problem of brute force is not feasible, because the data is too large, can be solved by mathematical methods, the odd number of even discussion, and then special case 2 also note 2 <= N <= 10 9 So all the data obtained by N will have to use __int64 to define the code as follows
#include <iostream>#include<cstdio>#include<vector>#include<algorithm>using namespacestd; intMain () {intT; CIN>>T;  while(t--) {__int64 n; CIN>>N; __int64 ans=0; if(n%2==0){            if(n = =2) ans=1; Else{                if(N/2) %2==0) {ans= (((N/2) -1) * (N/2+1)); }                Else{ans= (((N/2) -2) * (N/2+2)); }            }        }        Else{ans= (N/2* (N/2) +1)); } cout<< ans <<Endl; }    return 0;}
View Code

HDU 4627 The unsolvable problem problem-solving experience

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.