Advertisement
willy108

better cooked fish

Feb 3rd, 2022
1,192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. #define endl '\n'
  4. //#define int ll
  5. using namespace std;
  6. const int N=100010;
  7. const ll mod=1000000000000000001ll;
  8. void solve(){
  9.     ll n,k;cin>>n>>k;
  10.     if (k==1){
  11.         n*=2ll;
  12.         for (ll b=2;b*(b+1)<=n;b++){
  13.             if (n%b) continue;
  14.             ll a=n/b-(b+1);
  15.             if (a%2) continue;
  16.             a/=2ll;
  17.             cout<<a+1<<" "<<a+b+1<<endl;
  18.             return;
  19.         }
  20.         cout<<"-1 -1\n";
  21.         return;
  22.     }
  23.     if (k==2){
  24.         for (ll b=1;b*(b+1)*(2ll*b+1ll)/6ll<=n;b++){
  25.             ll c=b*(b+1ll)*(b+b+1ll)/6ll-n;
  26.             if (c%b) continue;
  27.             c/=b;
  28.             ll D=(b+1)*(b+1)-4ll*c;
  29.             if (D<0) continue;
  30.             ll g=sqrt(D);
  31.             if (g*g!=D) continue;
  32.             if ((g-b-1)%2) continue;
  33.             ll a=(g-b-1)/2ll;
  34.             if (a<0 || a>=n-1) continue;
  35.             cout<<a+1<<" "<<a+b+1<<endl;
  36.             return;
  37.  
  38.  
  39.         }
  40.         cout<<"-1 -1\n";
  41.         return;
  42.  
  43.     }
  44.  
  45.     vector<ll>v;
  46.     map<ll,ll>L;
  47.     L[0]=1;
  48.     ll sum=0ll;
  49.     for (ll i=1;;i++){
  50.         ll cur=1;
  51.         for (int j=0;j<k;j++) cur*=i;
  52.         if (cur>n) break;
  53.         sum+=cur;
  54.         sum%=mod;
  55.         if (L[(sum+mod-n%mod)%mod]){
  56.             cout<<L[(sum+mod-n%mod)%mod]<<" "<<i+1<<endl;
  57.             return;
  58.         }
  59.         L[sum]=i+1;
  60.     }
  61.     cout<<"-1 -1\n";
  62.  
  63. }
  64. int32_t main()
  65. {
  66.     srand(time(NULL));
  67.     ios_base::sync_with_stdio(false);
  68.     cin.tie(0);
  69.     int tt;cin>>tt;
  70.     while (tt--){
  71.         solve();
  72.     }
  73.     return 0;
  74. }
  75. //1 2 3 4 5
  76. // 2 3 4 4 3 2
  77. //1 1 1 1 1
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement