QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#884285 | #8336. Indeterminate Equation | manizare | WA | 126ms | 3712kb | C++20 | 2.2kb | 2025-02-05 23:31:47 | 2025-02-05 23:31:49 |
Judging History
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 = 1e5;
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: 12ms
memory: 3712kb
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: 114ms
memory: 3712kb
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: 126ms
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'