Codeforces Round 339 A.Link/Cut Tree

// Accepted.
// Link: Codeforces AC link of problem Link/Cut Tree

#include<bits/stdc++.h>

using namespace std;

#define fast ios_base::sync_with_stdio(false)
#define high 300010

typedef unsigned long long LL;

//LL power(LL x, int y)
//{
//    if(y == 0) return 1;
//
//    LL tmp = power(x, y/2);
//
//    if(y % 2 == 0)
//    {
//        return tmp * tmp;
//    }
//
//    else
//    {
//        return x * tmp * tmp;
//    }
//}


int main()
{
    fast;

//    LL x = 923523399718980912, y = 18686596544687500000;
//    string s = x > y ? "x boro" : "y boro";
//    cout << s;

    LL l, r, k;
    while(cin >> l >> r >> k)
    {
        bool f=false , yes=false;
        LL gtp=0;
        //cout << power(k, 5); return 0;

        for(int i=0; i<64; i++)
        {
            //gtp = power(k, i);
            gtp = powl(k, i);
            if(gtp > r) break;
            //cout << gtp << " " ;
            if(gtp >= l and gtp <= r)
            {
                if(!f)
                {
                    cout << gtp;
                    f=true;
                }

                else
                {
                    cout << " " << gtp ;
                }

                yes = true;
            }
        }

        if(!yes) cout << "-1";

        cout << "\n";
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number