Educational Codeforces Round 7 A
Description
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 number 1 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 number 10 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.
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 the long long integer type and in Java you can use long integer type.
Print the element in the n-th position of the sequence (the elements are numerated from one).
3
2
5
2
10
4
55
10
56
1
没什么好说的,先是一个等差数列求和,然后判断一下就行,如果等于一个和,说明一个循环结束,不是就减去
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
int t;
int n,m;
int sum,ans,flag;
int a,b,c,d;
int main()
{
LL n;
LL b;
LL ans;
LL i=0;
LL sum=0;
cin>>n;
while(sum<=n)
{
i++;
sum=1*i+(i)*(i-1)/2;
// i++;
}
// cout<<i-1<<endl;
ans=i-1;
// cout<<1*ans+(ans)*(ans-1)/2<<endl;
b=1*ans+(ans)*(ans-1)/2;
if(n==1*ans+(ans)*(ans-1)/2)
{
cout<<ans<<endl;
}
else
{
cout<<n-b<<endl;
}
return 0;
}
Educational Codeforces Round 7 A的更多相关文章
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [Educational Codeforces Round 16]B. Optimal Point on a Line
[Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- Educational Codeforces Round 6 C. Pearls in a Row
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
- Educational Codeforces Round 9
Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
随机推荐
- Result Maps、Auto-mapping、cache
1. Result Maps resultMap元素是Mybatis里面最重要的并且功能最强大的一个元素.(The resultMapelement is the most important an ...
- JVM知识点总览
jvm 总体梳理 jvm体系总体分四大块: 类的加载机制 jvm内存结构 GC算法 垃圾回收 GC分析 命令调优 当然这些知识点在之前的文章中都有详细的介绍,这里只做主干的梳理 这里画了一个思维导图, ...
- Nginx 正向代理和反向代理
正向代理的概念 正向代理,也就是传说中的代理,他的工作原理就像一个跳板,简单的说,我是一个用户,我访问不了某网站,但是我能访问一个代理服务器这个代理服务器呢,他能访问那个我不能访问的网站于是我先连上代 ...
- C++——virtual
一.放在父类的函数名前面:多态 1.作用:实现多态:子类可以自定义父类中的virtual函数 #include <iostream> using namespace std; class ...
- [转]MySQL5.6.22 安装
原文路径 http://jifeng3321.iteye.com/blog/2181517?utm_source=tuicool 由于一直做银行项目,所以一直在用oracle和db2,但最近自己想 ...
- sql中的Alias怎么用
一直很奇怪,不知道为什么sql的Alias怎么用,上次看到ThinkPHP中的讲解,为什么数据库在用的时候有时候喜欢改个别名再用, 因为昨天去参加了公司的数据库开发工程师的笔试,今天就复习一下sql, ...
- require()和include()代码重用
第五章 require()函数和include()函数几乎是相同的,二者唯一的区别在于函数失败后,require()函数将给出一个致命的错误,而include()只是给出一个警告. require_o ...
- SQL获取时间戳流水号
流水号生成规则: 1:流水号总长度为22位数 2:流水号总共分三部分:标头(2位)+ 时间戳(YYYYMMDDHHmmSSsss共17位)+ 随机码(3位) 举例流水号:SN2015081210240 ...
- 【摘自张宴的"实战:Nginx"】try_files指令
语法:try_files param1 [param2...paramN] fallback 默认值:none 使用环境: location 该指令用于告诉nginx测试每个文件是否存在,并且使用首先 ...
- Zbar 大图像分析
博客转载自:https://blog.csdn.net/sunflower_boy/article/details/50429252 为了减少处理时间,可以设定更大的扫描间距,减少不必要的解码类型,去 ...