zoukankan      html  css  js  c++  java
  • Codevs 1312 连续自然数和

    1312 连续自然数和

    题目描述 Description

    对于一个自然数M,求出所有的连续的自然数段,使得这些连续自然数段的全部数字和为M.
    eg:1998+1999+2000+2001+2002=10000,所以从1998到2002的一个自然数段为M=10000的一个解。 

    输入描述 Input Description

    一个数M

    输出描述 Output Description

    每行两个数,为连续自然数段的一头一尾,所有输出行的第一个数按照升序排列

    样例输入 Sample Input

    10000

    样例输出 Sample Output

    18 142

    297 328

    388 412

    1998 2002

    /*枚举起点判断行不行,好像还算快的*/
    #include<iostream>
    #include<cstdio>
    using namespace std;
    int n;
    int main(){
        int s,t;
        scanf("%d",&n);
        for(int i=1;i<n;i++){
            s=n;t=i;
            while(s>0)s-=t,t++;
            if(s==0)printf("%d %d
    ",i,t-1);
        }
    }
  • 相关阅读:
    [bzoj3123] [Sdoi2013]森林
    [bzoj2173] 整数的lqp拆分
    Linux
    使用高德地图API
    EF具体用在什么类型的项目上
    出现Data Tools 与VS 不兼容问题
    Entity FramWork
    Entity
    Entity
    BASH
  • 原文地址:https://www.cnblogs.com/thmyl/p/7077270.html
Copyright © 2011-2022 走看看