/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 484.0 KiB
#3 Accepted 1ms 512.0 KiB
#4 Accepted 1ms 536.0 KiB
#5 Accepted 1ms 532.0 KiB
#6 Accepted 1ms 440.0 KiB
#7 Accepted 1ms 532.0 KiB
#8 Accepted 1ms 320.0 KiB
#9 Accepted 1ms 528.0 KiB
#10 Accepted 1ms 532.0 KiB
#11 Accepted 1ms 536.0 KiB

Code

/*
Bismillahir Rahmanir Rahim
(In the name of Allah)

@Author Muhammad Nadim
*/

#include<bits/stdc++.h>
using namespace std;

#define     ll              long long
#define     ld              long double
#define     nl              '\n'
#define     pi              acos(-1.0)
#define     sp(n)           fixed<<setprecision(n)
#define     MNTDH_18        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define     yes             cout<<"YES"<<"\n"
#define     no              cout<<"NO"<<"\n"
#define     all(v)          v.begin(), v.end()
#define     CheckBit(x, k)  (x & (1LL << k))
#define     SetBit(x, k)    (x |= (1LL << k))
#define     ClearBit(x, k)  (x &= ~(1LL << k))
#define     LSB(mask)       __builtin_ctzll(mask)
#define     MSB(mask)       63-__builtin_clzll(mask) 

template <typename T, typename U> T ceil(T x, U y) {return (x > 0 ? (x + y - 1) / y : x / y);}
template <typename T, typename U> T floor(T x, U y) {return (x > 0 ? x / y : (x - y + 1) / y);}

//typedef  __int128 lll;
typedef struct rafi
{
    ll type;
    ll idx1;
    ll idx2;
}R;

typedef struct sajeeb
{
    ll val1;
    ll val2;
}S;

typedef struct ohi
{
    ll l;
    ll r;
    ll u;
    ll d;
    int val;
}O;

const int N=2e5+7, M=1073741824, N1=60;
ll p[N1];

void pow2()
{
    p[0]=1;
    for(int i=1; i<N1; i++) p[i]=2*p[i-1];
}

void sF()
{
    ll b, sqB;
    cin>>b;

    sqB=b*b;

    vector<ll> div;
    for(ll i=1; i*i<=sqB; i++)
    {
        if(sqB%i==0)
        {
            div.push_back(i);
            if(sqB/i!=i)    div.push_back(sqB/i);
        }
    }

    sort(all(div));

    for(int i=div.size()-1; i*2>div.size(); i--)
    {
        ll x=div[i], y=sqB/div[i];

        if(!((x+y)&1) && !((x-y)&1))
        {
            cout<<x+b<<nl;
            return;
        }
    }
    cout<<-1<<nl;
}

int main()
{
    MNTDH_18
    //pow2();

    int tc=1, cs=1;
    cin>>tc;
    
    while(tc--)
    {
        //cout<<"Case "<<cs++<<": ";
        sF();
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1027 Right triangle
Language
C++17 (G++ 13.2.0)
Submit At
2024-03-05 01:37:36
Judged At
2024-11-11 03:42:54
Judged By
Score
100
Total Time
1ms
Peak Memory
536.0 KiB