SCI representation

Topic Name: SCI representation

Topic links: SCI representation

description

Each positive integer N can be expressed as a number of consecutive positive integers, for example, 10 can be represented as 1 + 2 + 3 + 4 may be represented as 4,15 + 6,8 + 5 can be represented as 8 itself. We call this representation as SCI (Sum of Consecutive Integers) notation.

Hi I found a small integer SCI indicates there could be many, e.g. 15 can be represented as 1 + 2 + 3 + 4 + 5 + 5,4 + 6,7 + 8 and 15 themselves. SCI represents a small Hi all want to know the N, can contain up to how many consecutive positive integers. For example, 1 + 2 + 3 + 4 + 5 15 represents a positive integer of up comprising

Entry

A first line integer T, the number of the group representative test data.

The following T lines each a positive integer N.

Data for 30%, 1 ≤ N ≤ 1000

For 80% of data, 1 ≤ N ≤ 100000

To 100% of the data, 1 ≤ T ≤ 10,1 ≤ N ≤ 1000000000

Export

For each set of N data output represents the maximum number of integers SCI can contain.

Sample input

2
15
8

Sample Output

5
1

Problem-solving ideas

After the first glance that direct violence to solve it after the data range, looked definitely think time out, there must be a simple solution, read to understand after discussion, a number of settings, and the first item to item and a number of first determine whether an integer as a condition to obtain the maximum number of entries

The complete code

#include<bits/stdc++.h>
using namespace std;
 
int n,t,m,a;

int main()
{
	cin>>t;
	while(t--){
		cin>>n;
		for(int m=floor(sqrt(2*n));m>=1;m--){
			int k=2*n;
			if(k%m==0){
				if((k/m-m+1)%2==0){
					cout<<m<<endl;
					break;
				}
			}
		}
	}
	return 0;
}
Published 119 original articles · won praise 6 · views 10000 +

Guess you like

Origin blog.csdn.net/zhangdy12307/article/details/104149906