sgu 403. Scientific Problem

本文介绍了一个有趣的数学问题:给定一个整数x,如何找到一个整数N,使得N的x倍小于从1到N所有整数的总和。文章提供了一种简单有效的算法解决方案,并附带了C++实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


英语弱题意杀,给一个x找出一个N使N的x倍小于1到N的和。

可以有前N-1项和等于x*N,即2*x-1=n


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;



void solve(){
    int n;
    scanf("%d",&n);
    printf("%d",2*n+1);
}




int main() {


#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    solve();


    return 0;
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值