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