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. 利用JavaScriptCore实现以下简单的功能(平方和)

    #import "RootViewController.h" #import <JavaScriptCore/JavaScriptCore.h> @interface ...

  2. p3172 选数

    传送门 分析 对这个$f(k)$整除分块,用杜教筛搞出$\mu$的部分然后另一部分快速幂即可 代码 #include<iostream> #include<cstdio> #i ...

  3. Django框架 之 ORM查询操作详解

    Django框架 之 ORM查询操作详解 浏览目录 一般操作 ForeignKey操作 ManyToManyField 聚合查询 分组查询 F查询和Q查询 事务 Django终端打印SQL语句 在Py ...

  4. Flask框架 之 基本使用

    初识Flask Flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架,对于Werkzeug本质是Socket服务端,其用于接收http请求并对请求 ...

  5. Java Swing 创建转圈的进度提示框

    Java Swing 创建转圈的进度提示框 摘自 https://blog.csdn.net/nihaoqiulinhe/article/details/52439486 置顶2016年09月05日 ...

  6. 无需知道类名,就可以启动apk

    查看官方文档,发现这样一个方法: public abstract Intent getLaunchIntentForPackage (String packageName) 这个方法名就说明:根据包名 ...

  7. const 在C++中的区别

    一.Const作用    如下表所示: No. 作用 说明 参考代码 1 可以定义const常量 const int Max = 100; 2 便于进行类型检查 const常量有数据类型,而宏常量没有 ...

  8. SSH 前言(JDK静态代理和动态代理)

    代理模式:代理模式是为了增强目标对象 代理分静态代理和动态代理 静态代理逻辑是:比如定义一个ISomeService接口,接口里面有一个输出doSecond()的方法,然后目标类SomeService ...

  9. 关于redis-windows环境下的一些配置:

    如果报错: The Windows version of Redis allocates a memory mapped heap for sharing with the forked proces ...

  10. String类-小用

    字符串-string (1)string在Java中是一个引用类型,string变量可引用一个字符串对象 (2) 例1: s0,s1,s2引用同一个对象 New创建的两个string是不同的对象只是内 ...