Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int spr(long long p, long long q, long long x) {
- if (x > 1000000) return -1;
- long long a = x * x * x + p * x;
- if (a == q) return 0;
- if (a < q) return 1;
- else return -1;
- }
- void rozwiaz(long long p, long long q){
- long long poczatek = 0;
- long long srodek;
- int wartosc_spr;
- long long koniec = q / p + 1; //bo dzielenie zaokragla w dol wiec trzeba dodac
- while(poczatek < koniec){
- srodek = (poczatek + koniec) / 2;
- wartosc_spr = spr(p, q, srodek);
- if(wartosc_spr == 0){
- cout << srodek << endl;
- return;
- }
- else if(wartosc_spr == -1) koniec = srodek;
- else poczatek = srodek + 1;
- }
- cout << "NIE" << endl;
- }
- int main() {
- long long a;
- cin >> a;
- long long p, q;
- while(a--){
- cin >> p >> q;
- rozwiaz(p, q);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement