In the contest that has just ended, my code for problem D failed on testcase 6. This is my code:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
double n;
ll solve(){
double ans = (sqrt(1 + ll(8.0 * n)) - 1.0) / 2;
double ret = (ll)ans + ((ll)n - (ll)(ans + 1) * (ll)ans / 2);
return ll(ret + 1);
}
int main(){
int t;
cin >> t;
while(t--){
cin >> n;
cout << solve() << endl;
}
}
It works perfectly fine with case 1 to 5. The main idea of this program is to use the formula for quadratic functions to get the minimum value of $$$x$$$ such that $$$x * (x + 1) / 2$$$ is not larger than $$$n$$$.
Thx a lot to anyone who's willing to help me!!!
.
I'm perfectly sure that in my program x(x + 1)/2 is right. Otherwise it can't even pass case 1 ~ 5.