1465B - Fair Numbers - CodeForces Solution


brute force math number theory *1000

Please click on ads to support us..

C++ Code:

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

#define ll long long

#define endl "\n"
#define ite iterator
#define input(v)    \
      for (auto &v : v) \
      cin >> v
#define output(v)  \
      for (auto v : v) \
      cout << v << " "
#define Max_size 107374181
#define pb(n) push_back(n)
#define sortv(v) sort(v.begin(), v.end())
#define input2(v)     \
      for (auto &i : v)   \
        for (auto &a : i) \
      cin >> a
#define output2(v)      \
      for (auto &i : v)     \
      {                     \
        for (auto &a : i)   \
          cout << a << " "; \
        cout << "\n";       \
      }




void EssamGhanem()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}


//                                          Functions :



                // Problem Solution
vector<ll>binary_vec,anc , dic;
ll dic_binary (ll l , ll r  , ll key ){
    ll mid = (l+r)/2;
    if(r<l)
    {
        return -1;
    }
    if(dic[mid]==key)
    {
        return mid;
    }
    else if(dic[mid] > key )
    {
        return dic_binary(mid+1,r ,key);

    }
    else if (dic[mid]<key)
    {

        return dic_binary(l , mid-1, key);
    }


return 0 ;


}

ll anc_binary (ll l , ll r  , ll key )
{
    ll mid = (l+r)/2;

    if(r<l)
    {
       return -1;
    }


    if(anc[mid]==key)
    {
        return mid;
    }
    else if(anc[mid] > key )
    {

        return anc_binary(l , mid-1, key);
    }
    else if (anc[mid]<key)
    {

        return anc_binary(mid+1,r ,key);
    }


return 0;


}


void solve() {

ll n ;
ll index = 1,d,flag =1;
cin >> n;

while(flag)
{
    index=1;
    while(index <= n)
    {
        index*=10;
        d=(n%index)/(index/10);
        if(d==0)
            continue;
        if(n%d !=0)
        {
            n++;
            flag=1;
            break;

        }

        flag=0;
    }


}
cout << n<<endl;




}








//       ************************************************************************************

//                       #      main      #

int main()
{
     EssamGhanem();
     ll t = 1;
     cin >> t;
     while(t--)
     {
         solve();
     }
}


Comments

Submit
0 Comments
More Questions

780C - Andryusha and Colored Balloons
1153A - Serval and Bus
1487C - Minimum Ties
1136A - Nastya Is Reading a Book
1353B - Two Arrays And Swaps
1490E - Accidental Victory
1335A - Candies and Two Sisters
96B - Lucky Numbers (easy)
1151B - Dima and a Bad XOR
1435B - A New Technique
1633A - Div 7
268A - Games
1062B - Math
1294C - Product of Three Numbers
749A - Bachgold Problem
1486B - Eastern Exhibition
1363A - Odd Selection
131B - Opposites Attract
490C - Hacking Cypher
158B - Taxi
41C - Email address
1373D - Maximum Sum on Even Positions
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