奇怪的数列

奇怪的数列

TimeLimit:1000MS  MemoryLimit:128MB

64-bit integer IO format:%lld

已解决 | 点击收藏

收藏题目

备注

Close确定

Problem Description

HOME_W发现了一个奇怪的数列,是长这样子的。(数列的下标从1开始)

1,1,2,1,2,3,1,2,3,4,1,2,3,4,5,1,2,3,4,5,6,1,2,3,4,5,6,7,1,2,3,4,5,6,7,8……

聪明的HOME_W 一眼就发现这个数列的规律,现在想要考考你

Input

单组数据。

输入仅包含一个整数n

1<=n<=1018

请注意看标题下方的这句话  64-bit integer IO format:%lld

Output

输出的数列的第n项

SampleInput

999999999

SampleOutput

38439

Submit

题解:

‘1’——1,   

1,‘2’——3,   

1,2,‘3’——6,   

1,2,3,‘4’——10,   

1,2,3,4,‘5’——15,   

1,2,3,4,5,‘6’——21, 

二分每个引号引起来的数;

#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<bitset>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define eps (1e-8)
#define MAX 0x3f3f3f3f
#define u_max 1844674407370955161
#define l_max 9223372036854775807
#define i_max 2147483647
#define re register
#define pushup() tree[rt]=tree[rt<<1]+tree[rt<<1|1]
using namespace std;

inline int read(){
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' & c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

typedef long long ll;
const int M=2e5+5;
const int N=2e6+5;
ll n;
bool C(ll mid){
    return ((1+mid)*mid/2)>=n;
}
int main(){
    scanf("%lld",&n);
    if(n==1){
        printf("1\n");
        return 0;
    }
    ll l=1,r=1e10;
    while(r-1>l){
        ll mid=l+r>>1;
        if(C(mid)) r=mid;
        else l=mid;
    }
    ll sum=(r+1)*(r)/2;
    //printf("sum === %lld\n",sum);
    printf("%lld\n",r-(sum-n));
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值