clocosacide's blog

By clocosacide, history, 16 months ago, In English

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!!!

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By clocosacide, history, 17 months ago, In English

It's just a mark of my first participation in contest. I got 419 :)

Full text and comments »

  • Vote: I like it
  • +9
  • Vote: I do not like it