A NOD of 1138 consecutive integers and (simple mathematical formula)

Source: Internet
Author: User

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)

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.