• SGU


    403. Scientific Problem

    Time limit per test: 0.25 second(s)
    Memory limit: 65536 kilobytes
    input: standard
    output: standard



    Once upon a time Professor Idioticideasinventor was travelling by train. Watching cheerless landscape outside the window, he decided to invent the theme of his new scientific work. All of a sudden a brilliant idea struck him: to develop an effective algorithm finding an integer number, which is x times less than the sum of all its integer positive predecessors, where number x is given. As far as he has no computer in the train, you have to solve this difficult problem.

    Input
    The first line of the input file contains an integer number x (1 ≤ x ≤ 109).

    Output
    Output an integer number — the answer to the problem.

    Example(s)
    sample input
    sample output
    1
    
    3
    

    sample input
    sample output
    2
    
    5
    




    Online Contester Team © 2002 - 2010. All rights reserved.




    思路:先给出一个数x。求出数n,使得n是n之前全部数(不包含n)的总和的1/x

    由求和公式n*(n-1)/2/x = n 可得 n=2*x+1


    AC代码:

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    
    int main() {
    	int x;
    	while(scanf("%d", &x) != EOF) {
    		printf("%d
    ", 2*x+1);
    	}
    	return 0;
    } 















  • 相关阅读:
    DNN 4.9补丁
    15款经典图表软件推荐 创建最漂亮的图表
    在.NET使用JSON作为数据交换格式
    JQuery 动态删除
    在ASP.NET中使用Highcharts js图表
    一个比较好的工具网站
    DataTable与实体类互相转换
    第一次写JQuery页面
    一个代码查询网址
    NioEventLoop
  • 原文地址:https://www.cnblogs.com/wzzkaifa/p/7100570.html
Copyright © 2020-2023  润新知