#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int main(){
//~ freopen("file.in", "r", stdin);
ll n;
scanf("%lld",&n);
assert(n<=1e18);
if(n==1){
puts("1");
return 0;
}
int BLOK=sqrt(2*n);
for(int i=BLOK;i>=0;i--)
if(i*1LL*(i+1)/2LL+(i+1)<n){
ll ans=i*1LL*(i+1)+(i+1);
n-=i*1LL*(i+1)/2LL+(i+1);
if(n==1){
printf("%lld\n",ans+1);
return 0;
}n--;ans++;
printf("%lld\n",ans+n*2LL);
break;
}
return 0;
}
Compilation message
oddeven.cpp: In function 'int main()':
oddeven.cpp:23:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&n);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2028 KB |
Output is correct |
2 |
Correct |
0 ms |
2028 KB |
Output is correct |
3 |
Correct |
0 ms |
2028 KB |
Output is correct |
4 |
Correct |
0 ms |
2028 KB |
Output is correct |
5 |
Correct |
0 ms |
2028 KB |
Output is correct |
6 |
Correct |
0 ms |
2028 KB |
Output is correct |
7 |
Correct |
0 ms |
2028 KB |
Output is correct |
8 |
Correct |
0 ms |
2028 KB |
Output is correct |
9 |
Correct |
0 ms |
2028 KB |
Output is correct |
10 |
Correct |
0 ms |
2028 KB |
Output is correct |
11 |
Correct |
0 ms |
2028 KB |
Output is correct |
12 |
Correct |
0 ms |
2028 KB |
Output is correct |
13 |
Runtime error |
0 ms |
2032 KB |
Execution killed because of forbidden syscall gettid (186) |
14 |
Halted |
0 ms |
0 KB |
- |