eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Счастливые числа

опубликовано 15.03.2023, 11:27:44

salam

опубликовано 10.02.2024, 12:45:27

include <bits/stdc++.h>

typedef long double ld;

define p64 pair<ll,ll>

define pdd pair<double,double>

define lcm(a, b) ((a/gcd(a,b))*b)

define forn(i,n) for(int i=0 ; i<n; i++)

define forsn(i,s,n) for(ll i = s; i < n; i++)

define rforn(i,s) for(ll i = s; i >= 0; i--)

define rforsn(i,s,n) for(ll i = s; i >= n; i--)

define ln "\n"

define dbg(x) cout<<#x<<" = "<<x<<ln

define ll long long

define vint vector<int>

define vs vector<string>

define sint set<int>

define ss set<string>

define mint map<int, int>

define lb lower_bound

define ub upper_bound

define ins insert

define F first

define S second

define yes cout << "Yes\n"

define no cout << "No\n"

define ins insert

define TADICONFIRE iosbase::syncwith_stdio(false); cin.tie(0); cout.tie(0);

/** WRITEN BY YOU ░█████╗░░░░░░░░░░░░░░░ ██╔══██╗░░██╗░░░░██╗░░ ██║░░╚═╝██████╗██████╗ ██║░░██╗╚═██╔═╝╚═██╔═╝ ╚█████╔╝░░╚═╝░░░░╚═╝░░ ░╚════╝░░░░░░░░░░░░░░░

**/

define ull unsigned long long

define en "\n"

define pb push_back

define INF 1001

define ll long long

define fr(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))

define ld long double

define ull unsigned long long

define maximum 9223372036854775807

define minimum -maximum

define ld long double

define sz(x) (int)(x).size()

const ll sz=2e5+5; using namespace std; void solve(ll n) { ll b=0; ll p=4; while (b+p<n) { b+=p; p*=4; } p/=4; n-=b; string s=""; while (p>0) { s+=to_string((pow(2, n - 1)/p)); if(n%p==0) { n=p; } else { n%=p; } p/=4; } cout<<s<<en; } void solve2(ll n) { string ah=to_string(n); int f=-1; for (int i=0; i<ah.size(); i++) { if (ah[i]=='9') { break; }

    if (ah[i]!='1' and ah[i]!='2' and ah[i]!='4' and ah[i]!='8')
    {
        f=i;
        break;
    }
    else if (ah[i]!='8')
    {
        f=i;
    }
}

if (f==-1)
{
    for (int i=0; i<=ah.size(); i++)
    {
        cout << 1;
    }
    cout<<en;
    return;
}
ll i=f;
ah[i]++;
while (ah[i]!='1' and ah[i]!='2' and ah[i]!='4' and ah[i]!='8')
{
    ah[i]++;
}
for (i++; i < ah.size(); i++)
{
    ah[i] = '1';
}

cout<<ah<<en;

} int main() { TADICONFIRE; ll t; cin>>t; while(t--) { ll test; cin>>test; if (test==1) { cin>>test; solve(test); } else { cin>>test; solve2(test); } } }

опубликовано 10.02.2024, 22:48:55

Sayad_Salmanov1 dan kocure bilene halal olsun