A. Link/Cut Tree
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 lr and k, you need to print all powers of number k within range from l to rinclusive. 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).

Sample test(s)
input
  1. 1 10 2
output
  1. 1 2 4 8
input
  1. 2 4 5
output
  1. -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.

题意:给你一个区间[l,r]和一个数k,求k^0,k^1,k^2这些数字中处于该区间的数,并输出这些数

错因分析:看到题目第一反应就是想到了快速幂,然后迅速的写了上去,结果后来才意识到

快速幂会犯一个比较麻烦的的错误;直接将数相乘就好了嘛,干嘛要那么麻烦的快速幂,定势思维了

下面第一个是AC代码

  1. #include<cstdio>
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <cstdlib>
  6. #include <cmath>
  7. #include <vector>
  8. #include <queue>
  9. #include<map>
  10. #include <algorithm>
  11. #include <set>
  12. using namespace std;
  13. #define MM(a) memset(a,0,sizeof(a))
  14. typedef long long LL;
  15. typedef unsigned long long ULL;
  16. const int mod = 1000000007;
  17. const double eps = 1e-10;
  18. const int inf = 0x3f3f3f3f;
  19. int main()
  20. {
  21. long long l,r,v;
  22. while(~scanf("%lld %lld %lld",&l,&r,&v))
  23. {
  24. int flag=0;long long ans=1;
  25. while(ans<=r)
  26. {
  27. if(ans>=l)
  28. {
  29. flag=1;
  30. printf("%lld ",ans);
  31. }
  32. if(r/v>=ans)/*写成乘的形式是可能会爆long long的
                     因此是错误的额*/
              ans*=v;
  33. else
  34. break;
  35. }
  36. if(!flag)
  37. printf("-1");
  38. printf("\n");
  39. }
  40. return 0;
  41. }

  下面是wa的代码注意WA原因是不太好避免上面指出的那个错误:

  1. #include<cstdio>
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <cstdlib>
  6. #include <cmath>
  7. #include <vector>
  8. #include <queue>
  9. #include<map>
  10. #include <algorithm>
  11. #include <set>
  12. using namespace std;
  13. #define MM(a) memset(a,0,sizeof(a))
  14. typedef long long LL;
  15. typedef unsigned long long ULL;
  16. const int mod = 1000000007;
  17. const double eps = 1e-10;
  18. const int inf = 0x3f3f3f3f;
  19. long long cimi(long long a,long long p)
  20. {
  21. long long res=1,temp=a;
  22. while(p)
  23. {
  24. if(p&1)
  25. res*=temp;
  26. temp*=temp;
  27. p>>=1;
  28. }
  29. return res;
  30. }
  31. int main()
  32. {
  33. long long l,r,v;
  34. while(~scanf("%lld %lld %lld",&l,&r,&v))
  35. {
  36. int flag=0;long long ans=0;
  37. for(long long i=0;;i++)
  38. {
  39. ans=cimi(v,i);
  40. if(ans>=l&&ans<=r)
  41. {
  42. printf("%lld ",ans);
  43. flag=1;
  44. }
  45. else if(ans>r)
  46. break;
  47. }
  48. if(!flag)
  49. printf("-1");
  50. printf("\n");
  51. }
  52. return 0;
  53. }

  

614A - Link/Cut Tree 数乘的更多相关文章

  1. CodeForces 614A Link/Cut Tree

    #include<cstdio> #include<cstring> #include<cmath> #include<stack> #include& ...

  2. [CodeForces - 614A] A - Link/Cut Tree

    A - Link/Cut Tree Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, ...

  3. Link Cut Tree学习笔记

    从这里开始 动态树问题和Link Cut Tree 一些定义 access操作 换根操作 link和cut操作 时间复杂度证明 Link Cut Tree维护链上信息 Link Cut Tree维护子 ...

  4. link cut tree 入门

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

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

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

  6. Link/cut Tree

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

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

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

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

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

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

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

随机推荐

  1. python_0基础开始_day10

    第十节 一.函数进阶 动态参数 *a r g s —— 聚合位置参数,动态位置参数 默认返回的是tuple元组 def eat(*args):  # 函数的定义阶段 *聚合(打包)    print( ...

  2. 如何在LinuxKernel中操作file(set_fs與get_fs)

    在Kernel 中,照理說能存取至 0 ~ 4GB.但是實作層面卻是只能讓我們使用到3GB ~ 4GB 這會導致我們無法使用open(),write()這些在user space下的function. ...

  3. 用纯 CSS 创作一个在容器中反弹的小球

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/jKVbyE 可交互视频教 ...

  4. Codeforces 1201C. Maximum Median

    传送门 看到中位数考虑先把数排序一下 然后有个显然的贪心,一个数增加后一定不能比下一个数大,不然我们直接增加下一个数显然更优 所以初始时的中位数操作后也是中位数 那么我们只要考虑中间再往后怎么加使得答 ...

  5. Hadoop组成架构

    Hadoop是apache用来“处理海量数据存储和海量数据分析”的分布式系统基础架构,更广义的是指hadoop生态圈.Hadoop的优势 高可靠性:hadoop底层维护多个数据副本,即使某个计算单元故 ...

  6. MySQL性能优化(一):优化方式

    原文:MySQL性能优化(一):优化方式 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/v ...

  7. Auto-increment 自动增长

    Auto-increment 会在新记录插入表中时生成一个唯一的数字. AUTO INCREMENT 字段 我们通常希望在每次插入新记录时,自动地创建主键字段的值. 我们可以在表中创建一个 auto- ...

  8. vue iview表格应用

    今天看一下iview表格的使用.本文中有以下内容 table的必备部分(columns,data) render函数的使用(判断,添加样式,动态添加class...) slot使用 主要讲render ...

  9. 红色警戒2CE修改教程

    在大学的时候特别喜欢玩游戏,尤其偏爱单机游戏.在玩一些单机游戏的时候,特意使用了一些修改工具.本来是打算做成一个系列的,但是现在由于时间问题,仅介绍一些.(大概包括rimworld,饥荒,放逐之城,缺 ...

  10. Linux Exploit系列之二 整数溢出

    整数溢出 虚拟机安装:Ubuntu 12.04(x86) 什么是整数溢出? 存储大于最大支持值的值称为整数溢出.整数溢出本身不会导致任意代码执行,但整数溢出可能会导致堆栈溢出或堆溢出,这可能导致任意代 ...