/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 444.0 KiB
#2 Accepted 28ms 588.0 KiB
#3 Accepted 6ms 588.0 KiB

Code

#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define ll long long int
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define mx_ele(v) *max_element(v.begin(),v.end())
#define mnm_ele(v) *min_element(v.begin(),v.end())
#define endl "\n"
using namespace std;
void smile()
{
    int m,n;
    cin>>m>>n;
    int mnm=min(m,n);
    if(m%2==0 and n%2!=0)
        cout<<"-1\n";
    else if(m%2!=0 and n%2==0)
        cout<<"-1\n";

    else
    {
        if(m%2==0)
        {
            cout<<2<<endl;
        }
        else if(m%2!=0)
        {
            if(mnm==1)
                cout<<"-1\n";
            else
            {
                int ans=0;
                int flag=0;
                for(int i=3; i<=mnm; i+=2)
                {
                    if(m%i==0 and n%i==0)
                    {
                        flag=1;
                        ans=i;
                        break;
                    }
                }
                if(flag==1)
                cout<<ans<<endl;
                else
                cout<<"-1\n";
            }
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T=1;
    cin>>T;
    while(T--)
    {
        smile();
    }

}

Information

Submit By
Type
Submission
Problem
P1011 LCD
Contest
Brain booster - 1
Language
C++17 (G++ 13.2.0)
Submit At
2023-12-31 14:42:59
Judged At
2024-11-11 03:46:11
Judged By
Score
100
Total Time
28ms
Peak Memory
588.0 KiB