Description

Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.

Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)

Given integers l, r and k, you need to print all powers of number k within range from l to r inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!

Input

The first line of the input contains three space-separated integers l, r and k (1 ≤ l ≤ r ≤ 1018, 2 ≤ k ≤ 109).

Output

Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).

Sample Input

1 10 2

2  4  5

Sample Output

1 2 4 8

-1

此题非常要注意什么时候循环结束,否则可能会爆long long

#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
using namespace std;
LL powll(LL x, LL n)
{
LL pw = 1;
while (n > 0)
{
if (n & 1)
pw *= x;
x *= x;
n >>= 1;
}
return pw;
}
int main()
{
LL l,r,k;
LL x;
cin>>l>>r>>k;
int flag=0;
for(int i=0;i<=66;i++)
{
if(x>r/k) break;
x=powll(k,i);
if(x>=l&&x<=r)
{
flag=1;
cout<<x<<" ";
}
}
if(flag==0)
{
puts("-1");
}
return 0;
}

  

Codeforces Round #339 (Div. 2) A的更多相关文章

  1. Codeforces Round #339 (Div.2)

    A. Link/Cut Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  2. Codeforces Round #339 (Div. 1) A. Peter and Snow Blower 计算几何

    A. Peter and Snow Blower 题目连接: http://www.codeforces.com/contest/613/problem/A Description Peter got ...

  3. Codeforces Round #339 (Div. 2) B. Gena's Code 水题

    B. Gena's Code 题目连接: http://www.codeforces.com/contest/614/problem/B Description It's the year 4527 ...

  4. Codeforces Round #339 (Div. 2) A. Link/Cut Tree 水题

    A. Link/Cut Tree 题目连接: http://www.codeforces.com/contest/614/problem/A Description Programmer Rostis ...

  5. Codeforces Round #339 (Div. 1) C. Necklace 构造题

    C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...

  6. Codeforces Round #339 (Div. 1) B. Skills 暴力 二分

    B. Skills 题目连接: http://www.codeforces.com/contest/613/problem/B Description Lesha plays the recently ...

  7. Codeforces Round #339 Div.2 C - Peter and Snow Blower

    Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. A ...

  8. Codeforces Round #339 Div.2 B - Gena's Code

    It's the year 4527 and the tanks game that we all know and love still exists. There also exists Grea ...

  9. Codeforces Round #339 Div.2 A - Link/Cut Tree

    第一次正式参加常规赛想想有些小激动的呢 然后第一题就被hack了 心痛 _(:зゝ∠)_ tle点在于越界 因此结束循环条件从乘变为除 done //等等 这题没过总评 让我静静........ // ...

随机推荐

  1. java,js判断全角半角

    function chkHalf(str){ for(var i=0;i { strCode=str.charCodeAt(i); if((strCode>65248)||(strCode==1 ...

  2. IE6中浮动双边距bug

    想要创建出漂亮的网页设计, 除了要认真学习每一个html和CSS代码之外,不可能不去了解一下臭名昭著的IE6和更早的那些IE浏览器的坏脾气,因为你本来写出的规规矩矩的代码, 漂亮的设计就此就要完成了, ...

  3. Android禁止程序自动旋转的配置

    在想要禁止的Activity中加入 android:screenOrientation="portrait" 属性,其中,portrait是竖屏,landscape是横屏

  4. Maven学习笔记2-maven命令

    help:active-profiles列出当前构建中活动的Profile(项目的,用户的,全局的). help:effective-pom显示当前构建的实际POM,包含活动的Profile. hel ...

  5. HDU 6397(2018多校第8场1001) Character Encoding 容斥

    听了杜教的直播后知道了怎么做,有两种方法,一种构造函数(现在太菜了,听不懂,以后再补),一种容斥原理. 知识补充1:若x1,x2,.....xn均大于等于0,则x1+x2+...+xn=k的方案数是C ...

  6. 面试题:hibernate第三天 一对多和多对多配置

    1.1 一对多XML关系映射 1.1.1 客户配置文件: <?xml version="1.0" encoding="UTF-8"?> <!D ...

  7. ROS Learning-019 learning_tf-03(编程) 添加额外的坐标系 (Python版)

    ROS Indigo learning_tf-03 添加额外的坐标系 (Python版) 我使用的虚拟机软件:VMware Workstation 11 使用的Ubuntu系统:Ubuntu 14.0 ...

  8. css选择器的一些说明

    标签选择器.ID选择器.类选择器 这三个很简单,没啥可说的. 子选择器得说一下. <ul class="food">    <li>水果        &l ...

  9. SingletonPattern(23种设计模式之一)

    设计模式六大原则(1):单一职责原则 设计模式六大原则(2):里氏替换原则 设计模式六大原则(3):依赖倒置原则 设计模式六大原则(4):接口隔离原则 设计模式六大原则(5):迪米特法则 设计模式六大 ...

  10. protocol buffers的使用示例

    protocol buffers的使用示例 如果不了解protocol buffers,可以先参看:http://blog.csdn.net/zhu_xun/article/details/19343 ...