Transmission Door
1138 consecutive integers and
Base time limit: 1 seconds space limit: 131072 KB
A positive integer n is given, and N is written as a number of consecutive numbers and forms (length >= 2). For example, n = 15, can be written as 1 + 2 + 3 + 4 + 5, can also be written as 4 + 5 + 6, or 7 + 8. If it cannot be written as a number of consecutive integers, the output is no solution.
Input
Enter 1 number n (3 <= n <= 10^9).
Output
Outputs the 1th number in a continuous integer, and if there are more than one order of ascending order, the output no solution if it cannot be decomposed into a number of consecutive integers.
Input example
15
Output example
1
4
7
Problem Solving Ideas:
Because it's a sequential sequence so he must be a arithmetic progression with a tolerance of 1, then the input x will satisfy
x=N? a 1 +n ( n 1 span class= "Mo" id= "mathjax-span-2338" style= "Font-family:mathjax_main;" >) 2
So what we're asking for is A1, so A1 can solve it:
a1=2?x? n 2 +N 2? N
So we just have to start judging from 2*SQRT (n). for (int i=sqrt (n) * *; i>=2; i –)
And because it can't be a single number, it's >=2.
My Code:
#include <iostream>#include <cmath>#include <cstdio>using namespace Std;intMain () {intN while(cin>>n) {int m= (int)sqrt(n);intsum =0; for(intI=m * *; i>=2; i--) {if( (2*n+i-i*i)%(2*i)==0&& (2*n+i-i*i) >0) {cout<< (2*n+i-i*i)/(I * *) <<endl; sum++; } }if(!sum) puts ("No Solution"); }return 0;}
A NOD of 1138 consecutive integers and (simple mathematical formula)