A - Link/Cut Tree

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

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 lr 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 lr 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).

Example

Input
1 10 2
Output
1 2 4 8 
Input
2 4 5
Output
-1

Note

Note to the first sample: numbers 20 = 1, 21 = 2, 22 = 4, 23 = 8 lie within the specified range. The number 24 = 16 is greater then 10, thus it shouldn't be printed.

题目意思是,给你一个区间和一个数,求有几个这个数的正整数次幂在这个区间内.

由于数据很大,在判断是否超出R的时候可能会爆long long.所以在判断时不能用乘,而应该用除,这样就不会爆了.

 #include<cstdio>
 #include<algorithm>
 using namespace std;
 long long L,R,K;
 int main(){
     scanf("%lld%lld%lld",&L,&R,&K);
     ; ;
     ;}
     ; R/x>=K; i++){
         x*=K; ;}
     }
     ) puts("-1");
     ;
 }

[CodeForces - 614A] A - Link/Cut Tree的更多相关文章

  1. 【CodeForces 614A】Link/Cut Tree

    题 题意 给你一个区间,求里面有多少个数是k的次方. 分析 暴力,但是要注意这题范围会爆long long,当k=1e8: l=1:r=1e18时 k²=1e16,判断了是≤r,然后输出,再乘k就是1 ...

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

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

  3. 614A - Link/Cut Tree 数乘

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

  4. link cut tree 入门

    鉴于最近写bzoj还有51nod都出现写不动的现象,决定学习一波厉害的算法/数据结构. link cut tree:研究popoqqq那个神ppt. bzoj1036:维护access操作就可以了. ...

  5. Link/cut Tree

    Link/cut Tree 一棵link/cut tree是一种用以表示一个森林,一个有根树集合的数据结构.它提供以下操作: 向森林中加入一棵只有一个点的树. 将一个点及其子树从其所在的树上断开. 将 ...

  6. 洛谷P3690 Link Cut Tree (模板)

    Link Cut Tree 刚开始写了个指针版..调了一天然后放弃了.. 最后还是学了黄学长的板子!! #include <bits/stdc++.h> #define INF 0x3f3 ...

  7. LCT总结——概念篇+洛谷P3690[模板]Link Cut Tree(动态树)(LCT,Splay)

    为了优化体验(其实是强迫症),蒟蒻把总结拆成了两篇,方便不同学习阶段的Dalao们切换. LCT总结--应用篇戳这里 概念.性质简述 首先介绍一下链剖分的概念(感谢laofu的讲课) 链剖分,是指一类 ...

  8. bzoj2049 [Sdoi2008]Cave 洞穴勘测 link cut tree入门

    link cut tree入门题 首先说明本人只会写自底向上的数组版(都说了不写指针.不写自顶向下QAQ……) 突然发现link cut tree不难写... 说一下各个函数作用: bool isro ...

  9. P3690 【模板】Link Cut Tree (动态树)

    P3690 [模板]Link Cut Tree (动态树) 认父不认子的lct 注意:不 要 把 $fa[x]$和$nrt(x)$ 混 在 一 起 ! #include<cstdio> v ...

随机推荐

  1. pyqt笔记1模块 信号和插槽

    资料 PyQt5图形界面编程 PyQt5指南 模块 PyQt5本身拥有超过620个类和6000函数及方法. QtCore模块涵盖了包的核心的非GUI功能,此模块被用于处理程序中涉及到的 time.文件 ...

  2. 并发编程之IO模型

    一.阻塞IO(blocking IO) from concurrent.futures import ThreadPoolExecutor import socket server = socket. ...

  3. K-近邻

    概述 KNN算法本身简单有效,是一种lazy-learning算法: 分类器不需要使用训练集进行训练,训练时间复杂度为0: KNN分类的计算复杂度和训练集中的文档数目成正比,也就是说,如果训练集中文档 ...

  4. Pandas 基础(1) - 初识及安装 yupyter

    Hello, 大家好, 昨天说了我会再更新一个关于 Pandas 基础知识的教程, 这里就是啦......Pandas 被广泛应用于数据分析领域, 是一个很好的分析工具, 也是我们后面学习 machi ...

  5. 详细解说Tomcat 设置虚拟路径的几种方法及为什么设置虚拟路径

    说明:此次使用的是Tomcat 7.0 很多朋友都会很疑惑,既然我们都知道在Tomcat服务器上部署项目只要将项目打包,然后放到webapps目录下就可以了,为什么还需要配置虚拟路径?的确,把项目放到 ...

  6. in_array的三个参数

    needle 待搜索的值. haystack 待搜索的数组. strict 如果第三个参数 strict 的值为 TRUE 则 in_array() 函数还会检查 needle 的类型是否和 hays ...

  7. 力扣(LeetCode)389. 找不同

    给定两个字符串 s 和 t,它们只包含小写字母. 字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母. 请找出在 t 中被添加的字母. 示例: 输入: s = "abcd&quo ...

  8. DAY5 基本数据类型及内置方法

    一.可变与不可变数据类型 1.可变类型:值改变,但是id不变,证明就是在改变原值,是可变类型 2.不可变类型:值改变,但是id也跟着变,证明是产生了新的值,是不可变类型 二.数字类型 1.整型int ...

  9. tf一些函数

    1. tf.reduce_mean(a) : 求平均值 2. tf.truncated_normal([3,2],stddev=0.1) : 从正态分布中输出随机值,标准差为0,1,构造矩阵为3*2的 ...

  10. feed

    a1=tf.placeholder(tf.float32)    # 占位符 a2=tf.placeholder(tf.float32)r=tf.multiply(a1,a2) with tf.Ses ...