답안 #152346

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152346 2019-09-07T16:29:11 Z Breno_XD Uzastopni (COCI17_uzastopni) C++14
72 / 80
143 ms 476 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;

int n;
ll sum;
ll v1, v2;

ll gauss(ll k){

	if(k%2==0) return (k+1) * (k/2);
 	else return k * ((k+1)/2);
}

void buscabin(int x){

	ll ini = 1, meio, fim = 10e10;

	v1 = -1, v2 = -1;

	while(ini<=fim){

		meio = (ini+fim)/2;
		//cout << "ini: " << ini << "    fim: " << fim << "    meio: " << meio << "\n";
		
		if(meio-x < 0){
			ini = meio+1;
			continue;
		}

		ll sum = gauss(meio) - gauss(meio-x);

		if(sum == n){
			v1 = meio-x+1;
			v2 = meio;
			break;
		}

		if(sum > n) fim = meio-1;
		if(sum < n)	ini = meio+1;

	}

}

int main(){

	cin >> n;

	for(int i=2; i<=1000000; i++){

		buscabin(i);
		if(v1 != -1 && v1!=0) cout << v1 << " " << v2 << "\n";

	}

	return 0;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 392 KB Output is correct
2 Correct 141 ms 396 KB Output is correct
3 Correct 142 ms 376 KB Output is correct
4 Correct 141 ms 476 KB Output is correct
5 Correct 141 ms 376 KB Output is correct
6 Correct 141 ms 252 KB Output is correct
7 Correct 142 ms 256 KB Output is correct
8 Correct 142 ms 256 KB Output is correct
9 Correct 143 ms 256 KB Output is correct
10 Incorrect 142 ms 256 KB Output isn't correct