QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#884252#8336. Indeterminate EquationmanizareWA 242ms3712kbC++202.2kb2025-02-05 22:50:422025-02-05 22:50:42

Judging History

This is the latest submission verdict.

  • [2025-02-05 22:50:42]
  • Judged
  • Verdict: WA
  • Time: 242ms
  • Memory: 3712kb
  • [2025-02-05 22:50:42]
  • Submitted

answer

#include <bits/stdc++.h> 
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define pii pair<int,int> 
#define all(a) a.begin(),a.end()
#define S second 
#define sz(a) (int)a.size()
#define rep(i , a , b) for(int i = (a) ; i <= (b) ; i++)
#define per(i , a , b) for(int i = (a) ; i >= (b) ; i--)
#define ll long long
#define int __int128 
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 100+20 , maxm = 2e4 + 220, sq = 500 , inf = 1e9+10 , mod =998244353 ; 
int pw(int x ,int k){
    if(k==3)return x*x*x ; 
    if(k == 0)return 1; 
    int v = pw(x,k/2);
    v = v*v; 
    if(k&1) v = v*x;
    return v ;
}

signed main(){
    ios_base::sync_with_stdio(false) ; cin.tie(0) ;
    ll T ;
    cin >> T ;
    while(T--){
        ll n , k ;
        cin >> n >> k ;
        if(k >= 4){
            int x = 1 ; 
            int nw = 1 , ans =0  ;
            while(1){
                while(pw(nw , k)-pw(x, k) > n){
                    x++;
                }
                if(pw(nw , k) - pw(nw-1 , k) > n)break ;
                if(pw(nw, k)-pw(x,k) == n){
                    ans ++ ;
                }
                nw++;
            }
            ll x2 = ans ;
            cout << x2 << "\n"; 
            continue ; 
        }
        int x = 1 ; 
        int nw = 1 , ans =0 , f = 3e5;
        while(1){
            while(pw(nw , k)-pw(x, k) > n){
                x++;
            }
            if(nw >= f && pw(nw , k) - pw(nw-f , k) > n)break ;
            if(pw(nw, k)-pw(x,k) == n && nw - x > f){
                ans ++ ;
            }
            nw++;
        }
        rep(i , 1 , f){
            int l = 0 , r= (1e9+2)/i+2 ; 
            while(r-l > 1){
                int m = (l+r)/2 ;
                int a= i , b= m*m + (m+i)*(m+i) + (m+i)*m ;
                if(b <= n/a){
                    l = m ;
                }else{
                    r = m ;
                }
            }
            int m = l;
            int a= i , b= m*m + (m+i)*(m+i) + (m+i)*m ;
            if(a*b == n){
                ans++ ;
           }
        }
        ll x2= ans ;
        cout << x2 << "\n";
        
    }
}
/*
 
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 33ms
memory: 3584kb

input:

3
7 3
15 4
31 5

output:

1
1
1

result:

ok 3 number(s): "1 1 1"

Test #2:

score: 0
Accepted
time: 197ms
memory: 3584kb

input:

20
409013310800583799 32
70368744177663 46
592570256192463681 4
360020145419649 5
357385021818058297 3
950227088646484702 56
127 7
718303642731669822 3
651621023623339377 45
405657994164855469 3
4095 12
288230376151711743 58
224251587219143167 5
2221626677255791 3
2953488086475199 4
6672460861685157...

output:

0
1
1
1
1
0
1
0
0
1
1
1
1
1
1
1
0
1
0
0

result:

ok 20 numbers

Test #3:

score: -100
Wrong Answer
time: 242ms
memory: 3712kb

input:

20
299663213308337404 3
789663530028185253 15
899102550518872677 5
908651241968426417 38
10161731698203367 3
172563904510845597 3
24904219972305241 3
72057594037927935 56
900135928346130972 6
63 6
32370674179164127 3
638119226609365944 62
67108863 26
257821881508336320 3
815804918211865461 12
910411...

output:

1
0
1
0
1
0
1
1
0
1
1
0
1
0
0
0
1
0
1
1

result:

wrong answer 6th numbers differ - expected: '1', found: '0'