/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 532.0 KiB
#2 Accepted 5ms 324.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define optimize()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);//cout.tie(NULL);
#define fraction()                \
    cout.unsetf(ios::floatfield); \
    cout.precision(6);           \
    cout.setf(ios::fixed, ios::floatfield);
#define file()                        \
    freopen("input.txt", "r", stdin); \
    freopen("output", "w", stdout);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pr;
template <typename T> using ordered_set = tree <T, null_type,less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
int lcm(int a, int b)
{
    return (a * b) / __gcd(a, b);
}
int gcd(int a, int b)
{
    return __gcd(a, b);
}
#define el "\n"
const int mod = 1e9+7;
//const int mx = 5e5 + 125;

bool com(const pair<ll, ll> &p1, const pair<ll, ll> &p2)
{
    if (p1.first == p2.first) return p1.second < p2.second;
    return p1.first < p2.first;
}


const int mxx= 1e8;
bitset<mxx> isPrime;
vector<int> primes;
int mx=1e6+5;

map<int,int>m;

void primeGen ( int n )
{
    for ( int i = 3; i <= n; i += 2 ) isPrime[i] = 1;

    int sq = sqrt(n);
    for ( int i = 3; i <= sq; i += 2 )
    {
        if(isPrime[i])
        {
            for ( int j = i*i; j <= n; j += i )
            {
                isPrime[j] = 0;
            }
        }
    }

    primes.push_back(2);

    for ( int i = 3; i <= n; i += 2 )
    {
        if(isPrime[i] == 1)
        {
            primes.push_back(i);
        }
    }
}


long long power(int n)
{
    ll res=1;
    for(int i=0; i<n; i++)
    {
        res=(res*2);
    }
    return res;

}
void primeFactors ( int n ) /// n = 40131
{
    vector<int> factors;
    /// primes = 2, 3, 5, 7, 11, 13, 17, 19, 23
    if(isPrime[n]==0)
    {
        for ( auto p : primes )  /// p = 11
        {

            if( 1LL * p * p > n ) break;
            if( n % p == 0 )   /// n = 13, p = 7
            {
                m[p]++;
                while ( n % p == 0 )  /// n = 13, p = 7
                {
                    //factors.push_back(p); /// factors = { 3, 3, 7, 7, 7 }
                    n /= p; /// n = 13
                }
            }
        }
    }
    if(n > 1)
    {
        //factors.push_back(n);/// factors = { 3, 3, 7, 7, 7, 13 }
        m[n]++;
    }
}

/// calculating sum of divisors by prime factorization :

/*ll SOD(ll n)
{
    ll sod=1;
    ll mul=0;
    ll sum=0;
    for(auto x:primes)
    {
        if(1LL*x*x>n)break;
        if(n%x*1LL==0)
        {
             mul=1;
             sum=1;
            while (n%x*1LL==0)
            {
                mul*=x*1LL;
                sum+=mul;
                n/=x;
            }
            sod*=sum;

        }
       // sod*=sum;
    }
    if(n>1)sod*=(1+n);

    return sod;
}*/

/// for O(sqrt(n)) solution :
/*ll sod2(ll n)
{
    ll sum=0,i;
    for(i=1;i<=sqrt(n);i++)
    {
        ll cnt=(n/i)-i;
        sum+=cnt*2;
    }
    sum+=sqrt(n);
    return sum;

}*/

/// Calculating power of a^b :(Binary exponential method:O(log n))

/// Using iterative Form :(its Faster than the recursive process)

ll binary_exponential(ll a, ll b)
{
    a%=mod;
    ll result=1;
    while(b>0)
    {
        if(b&1)result=(result*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return result;
}

///  Modular multiplicative inverse :
/// Theory : A^(m�2)mod M = A^�1 mod M

/*ll modular_multiplicative_inverse(ll a,ll mod)
{
  ll ans=binary_exponential(a,mod-2) % mod;
  return ans;
}*/

void giveanswer()
{
   int a,b,i;
   cin>>a>>b;
   for(i=2;i<=100;i++)
   {
       if(i%a!=0 and i%b!=0)
       {
           cout<<i<<el;
           return;
       }

   }
   cout<<-1<<el;






}
int main()
{
    optimize();
    fraction();
    //primeGen(1e6);
    int t;
    cin>>t;
    for(int i=1; i<=t; i++)
   {
        giveanswer();
    }
}


Information

Submit By
Type
Submission
Problem
P1235 A. Valid Integer
Contest
Happy New Year 2026
Language
C++17 (G++ 13.2.0)
Submit At
2026-01-06 14:35:42
Judged At
2026-01-06 14:35:42
Judged By
Score
100
Total Time
5ms
Peak Memory
532.0 KiB