1603B - Moderate Modular Mode - CodeForces Solution


constructive algorithms math number theory *1600

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define in              insert
//#define mp              make_pair
#define len(s)          (int)s.size()
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
// #define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);


//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key

/*
//when using map with pair<int, int> as key
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);

        if (hash1 != hash2) {
            return hash1 ^ hash2;
        }

        // If hash1 == hash2, their XOR is zero.
          return hash1;
    }
};
*/

// int power(int x, int y){
//     int res = 1;
//     x = x % mod;
//     if (x == 0)
//         return 0;

//     while (y > 0){
//         if (y & 1)
//             res = (res*1LL*x) % mod;
//         y = y>>1;
//         x = (x*1LL*x) % mod;
//     }
//     return res;
// }

// int multiply(int a, int b){
//     int res = 0;
//     a %= mod;

//     while(b){
//         if(b & 1)
//             res = (res+ a)%mod;
//         a= (2* 1LL* a) % mod;
//         b>>= 1;
//     }
//     return res;
// }

/*
void primeFactors(int n, unordered_map<int, int>& mp){
    while(n%2== 0){
        mp[2]++;
        n = n/2;
    }
    for(int i= 3; i*i<= n; i+= 2){
        while(n%i== 0){
            mp[i]++;
            n = n/i;
        }
    }
    if(n> 2)
        mp[n]++;
}
*/
// int store[200001];
// int fac(int n){
//     if(store[n]!= -1)
//         return store[n];
//     if(n== 1 || n== 0)
//         return store[n]= 1;
//     return store[n]= (n* 1LL* fac(n-1))%mod;
// }

//SIEVE OF ERATOSTHENES
// const int N= 1e6+ 6;
// vector<int> isprime(N, 1);
// vector<int> sprime;
// void sieve(int n){
//     isprime[0]= isprime[1]= 0;
//     for(int i= 2; i<= n; ++i){
//         if(!isprime[i])
//             continue;

//         sprime.pb(i);
//         for(int j= i*i; j<= n; j+= i)
//             isprime[j]= 0;
//     }
// }

void solve(){
    int x,y; cin>>x>>y;
    if(x> y)
        cout<<x+y<<endl;
    else{
        cout<<y- y%x/2<<endl;
    }
}

int32_t main()
{
    fast_io;
    int t; cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1676G - White-Black Balanced Subtrees
1716D - Chip Move
1352F - Binary String Reconstruction
1487B - Cat Cycle
1679C - Rooks Defenders
56A - Bar
1694B - Paranoid String
35A - Shell Game
1684A - Digit Minimization
43B - Letter
1017A - The Rank
1698B - Rising Sand
235A - LCM Challenge
1075B - Taxi drivers and Lyft
1562A - The Miracle and the Sleeper
1216A - Prefixes
1490C - Sum of Cubes
868A - Bark to Unlock
873B - Balanced Substring
1401D - Maximum Distributed Tree
1716C - Robot in a Hallway
1688B - Patchouli's Magical Talisman
99A - Help Far Away Kingdom
622B - The Time
1688C - Manipulating History
1169D - Good Triple
1675B - Make It Increasing
588A - Duff and Meat
1541B - Pleasant Pairs
1626B - Minor Reduction