A. Link/Cut Tree

题目连接:

http://www.codeforces.com/contest/614/problem/A

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

Sample Output

1 2 4 8

Hint

题意

给你l,r,k

让你输出k在[l,r]里面的幂

题解:

很水的题,但是会爆long long

所以在乘的时候注意一下,或者用python就好了

代码

#include<bits/stdc++.h>
using namespace std; vector<long long> T;
int main()
{
long long l,r,k;
cin>>l>>r>>k;
int flag = 0;
long long tmp = 1;
while(tmp<=r)
{
if(tmp>=l)
{
T.push_back(tmp);
flag = 1;
}
if(r*1.0/tmp*1.0<k)
break;
tmp*=k;
}
if(!flag)cout<<"-1"<<endl;
else
{
for(int i=0;i<T.size();i++)
cout<<T[i]<<" ";
cout<<endl;
}
}

Codeforces Round #339 (Div. 2) A. Link/Cut Tree 水题的更多相关文章

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

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

  2. 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 ...

  3. Codeforces Round #594 (Div. 2) B. Grow The Tree 水题

    B. Grow The Tree Gardener Alexey teaches competitive programming to high school students. To congrat ...

  4. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  5. Codeforces Round #670 (Div. 2) C. Link Cut Centroids (dfs,树)

    C. Link Cut Centroids Fishing Prince loves trees, and he especially loves trees with only one centro ...

  6. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

  7. Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题

    A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  8. Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题

    B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...

  9. Codeforces Round #368 (Div. 2) A. Brain's Photos 水题

    A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...

随机推荐

  1. head 命令

    head 与 tail 就像它的名字一样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head 用来显示档案的开头至标准输出中,而 tail 想当然尔就是看档案的结尾. 1.命令格式: hea ...

  2. 6. ActionBar详解

    ActionBar简介  隐藏和显示ActionBar 隐藏ActionBar      getActionBar().hide(); 显示ActionBar      getActionBar( ...

  3. 图的邻接表存储表示(C)

    //---------图的邻接表存储表示------- #include<stdio.h> #include<stdlib.h> #define MAX_VERTEXT_NUM ...

  4. TortoiseSVN 插件配置及使用方法

    一.安装和配置 TortoiseSVN的下载地址 32bit:TortoiseSVN-1.8.2.24708-win32-svn-1.8.3.msi 64bit:TortoiseSVN-1.8.2.2 ...

  5. The remote SSH server rejected X11 forwarding request

    两台相同的虚拟机,一台没有错误,一个经常出现警告,内容如下所示: The remote SSH server rejected X11 forwarding request 找了很多方法,最后发现是安 ...

  6. Python编程中的反模式

    Python是时下最热门的编程语言之一了.简洁而富有表达力的语法,两三行代码往往就能解决十来行C代码才能解决的问题:丰富的标准库和第三方库,大大节约了开发时间,使它成为那些对性能没有严苛要求的开发任务 ...

  7. hadoop2.5.2学习及实践笔记(二)—— 编译源代码及导入源码至eclipse

    生产环境中hadoop一般会选择64位版本,官方下载的hadoop安装包中的native库是32位的,因此运行64位版本时,需要自己编译64位的native库,并替换掉自带native库. 源码包下的 ...

  8. SvUDID实现设备唯一标示

    //SvUDIDTools : https://github.com/smileEvday/SvUDID //将生成的UDID保存到钥匙串中,用户卸载app再重新安装UDID也不会改变. /* 用法1 ...

  9. POJ 3164 Command Network (最小树形图)

    [题目链接]http://poj.org/problem?id=3164 [解题思路]百度百科:最小树形图 ]里面有详细的解释,而Notonlysucess有精简的模板,下文有对其模板的一点解释,前提 ...

  10. URAL-1987 Nested Segments 线段树简单区间覆盖

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1987 题意:给定n条线段,每两条线段要么满足没有公共部分,要么包含.给出m个询问,求当前 ...