oj1066: Cube

Topics requirements
described
students as UESTC applied mathematics school, WCM like math. One day, he found an interesting theorem that every positive integer can be expressed as the sum of the cube of consecutive positive odd integers. For example, 11 * 11 * 11 = 1331 = 111 + 113 + 115 + 117 + 119 + 121 + 123 + 125 + 127 + 129 + 131 face so perfect theorem, the WCM thrilled. But he did not know how to prove it. He sought help from his good friend Tom Riddle (Tom Riddle). Tom Riddle (Tom Riddle) is a student of the American College of Computer Science, University of Electronic Science and Technology, specializes in programming. He uses a computer to easily prove the validity of the theorem. Is this okay? Given a positive integer N, you should determine how the numbers indicate this is a positive integer N number of consecutive odd and. You only need to output N integers in the minimum and maximum numbers can be.
Input value
of the first line of the input contains an integer that indicates the number of test cases. Each test case on a line contains a positive integer N (0 <N≤1000).
Output
For each test case, the output on line two integers, this is a positive integer N consecutive odd minimum and maximum numbers, the sum of N * N * N.
The Input the Sample
2
11
3
the Sample the Output
Raw
111 131 is
seven 11
cube and a number equal to the odd number of consecutive items, such as
8 = 3 + ...... 2 5
27 = 7 + 9 + 3 ...... 11
64 = 13 + 15 + ...... 19 17 + 4
125 = 21 + 23 + 25 + 27 + 29 ....... 5
16 = 31 + 33 + 35 + 37 + 39 + 41 ...... 6
because an odd digital sum is odd, an even number is an even number of digital addition
can be found that odd the numbers in the middle n*n*n/n, and the middle two numbers to an even number n*n*n/n*2
so long as we know the maximum value max and the minimum value intermediate digital min can be solved in accordance with the relationship between n and the intermediate-mid

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
	int n, m, t;
	cin >> n;
	while (n--)
	{
		cin >> m;
		t = m;
		long long max;
		max = m * m * m;
		int mid;
		mid = max / t;
		if(m%2==1)
			cout << mid - 2 * ((t - 1) / 2)<<" "<<mid+ 2 * ((t - 1) / 2) << endl;
		else
		{
			int left, right;
			left = mid - 1;
			right = mid + 1;
			if (left + right == max)
				cout << left << " " << right << endl;
			else
				cout << left - 2 * ((t - 1) / 2) << " " << right + 2 * ((t - 1) / 2) << endl;
		}
	}
	return 0;
}
Published 38 original articles · won praise 27 · views 3182

Guess you like

Origin blog.csdn.net/qq_45891413/article/details/104955359