1826C - Dreaming of Freedom - CodeForces Solution


greedy number theory

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define count_1(n)   __builtin_popcountll(n)
#define pb push_back
#define fr(a,b) for(int i =a ;i <b ;i++)
#define fr1(a,b) for(int j =a ;j <b ;j++)
#define all(x) (x).begin(), (x).end()
#define vint vector<int>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 1e9 + 7 ;
#define inf (1LL<<62)
template <typename T>istream &operator>>(istream &istream, vector<T> &vec){for (auto &a : vec)cin >> a;return istream;}     
template <typename T>ostream &operator<<(ostream &ostream, const vector<T> &vec){for (auto &a : vec)cout << a << " ";return ostream;}
long long binpow(long long a, long long b) {
long long res = 1;
    while (b > 0) {
        if (b & 1) res = res * a; a = a * a; b >>= 1;
    } return res;
}   

//==========================================-_-=============================================// 
ll smallestDivisor(ll n)
{
    if (n % 2 == 0)
        return 2;
    for (int i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }
 
    return n;
}
int main() {
    FAST
    ll t,n,m,x,j,k,q,d,e;
    t=1;
    cin>>t;
    while(t--){
        ll ans=0,a=0,b=0,l,r,mid;
      cin>>n>>m;
      if(m>=n&&n!=1){
          cout<<"no"<<endl;
      }
      else{
          if(n%m==0&&n!=1&&m!=1){
              cout<<"No"<<endl;
          }
          else if(n==1||m==1){
              cout<<"yes"<<endl;
          }
          else{
              k=smallestDivisor(n);
              
              if(k<=m&&k!=1){
                  cout<<"no"<<endl;
              }
              else cout<<"yes"<<endl;
          }
      }
    }
    return 0;
   }


Comments

Submit
0 Comments
More Questions

1574C - Slay the Dragon
621A - Wet Shark and Odd and Even
1395A - Boboniu Likes to Color Balls
1637C - Andrew and Stones
1334B - Middle Class
260C - Balls and Boxes
1554A - Cherry
11B - Jumping Jack
716A - Crazy Computer
644A - Parliament of Berland
1657C - Bracket Sequence Deletion
1657B - XY Sequence
1009A - Game Shopping
1657A - Integer Moves
230B - T-primes
630A - Again Twenty Five
1234D - Distinct Characters Queries
1183A - Nearest Interesting Number
1009E - Intercity Travelling
1637B - MEX and Array
224A - Parallelepiped
964A - Splits
1615A - Closing The Gap
4C - Registration System
1321A - Contest for Robots
1451A - Subtract or Divide
1B - Spreadsheet
1177A - Digits Sequence (Easy Edition)
1579A - Casimir's String Solitaire
287B - Pipeline