CodeForces 622A-Infinite Sequence

来源:互联网 发布:知乎回答怎么复制 编辑:程序博客网 时间:2024/04/27 07:18
A. Infinite Sequence
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number10 first appears in the sequence in position 55 (the elements are numerated from one).

Find the number on the n-th position of the sequence.

Input

The only line contains integer n (1 ≤ n ≤ 1014) — the position of the number to find.

Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use thelong long integer type and in Java you can use long integer type.

Output

Print the element in the n-th position of the sequence (the elements are numerated from one).

Examples
Input
3
Output
2
Input
5
Output
2
Input
10
Output
4
Input
55
Output
10
Input
56
Output
1
#include<stdio.h>#define LL __int64int main(){LL n;scanf("%I64d",&n);if(n==1){printf("1\n");}else{LL i,j=1;for(i=1;(i*(i+1))<2*n;i++){j=i;}j++;LL uu=j*(j-1)/2;printf("%I64d",n-uu); }return 0;} 


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 sql数据库满了怎么办 微信充值话费不到账怎么办 填报志愿密码错误怎么办 校园卡被冻结了怎么办 充值卡密码丢了怎么办 联通手机号码不支持开黄钻怎么办 手机qq加载失败怎么办 qq红包额度上限怎么办 qq红包超出限额怎么办 qq红包超过限额怎么办 红包过期没退回怎么办 qb充值错了号码怎么办 天猫q币充值被骗怎么办 微信充错了q币怎么办 qq钱包没银行卡怎么办 qq钱包被限制怎么办 充流量未到账怎么办 云客服被冻结怎么办 联通话费注销了怎么办 我的话费太多怎么办 lol充错账号怎么办 支付宝手机充值没到账怎么办 支付宝限额10000怎么办 米币超过限制怎么办 忘记财付通支付密码怎么办 支付宝忘记登陆密码怎么办 三位数密码忘记了怎么办 登入密码忘记怎么办 电脑登录忘记密码怎么办 支付宝忘记密码怎么办 密码箱忘了密码怎么办 信用卡忘了密码怎么办 我没有财付通钱没有了怎么办 发红包忘记密码怎么办 手机怎么办理财付通 忘记qq红包密码怎么办 财付通自动扣费怎么办 qq钱包注销了怎么办 获取验证码失败怎么办 火山充值上限怎么办 手机网银转账户怎么办