51nod1138 连续整数的和

来源:互联网 发布:macbook 自带软件 编辑:程序博客网 时间:2024/05/18 00:02

照网上学的,用等差数列的第N项以及 和来推导,记录下来以后自己再重新写一遍

#include <iostream>#include <stdio.h>#include <math.h>using namespace std;int main(){    int n;    cin>>n;    int tep=sqrt(n*2+1);    int over=0;    for(int i=tep;i>=2;i--)    {        if((n-i*(i-1)/2)%i==0)        {            over=1;            printf("%d\n",(n-i*(i-1)/2)/i);        }    }    if(!over)        printf("No Solution\n");    return 0;}


0 0