Your goal in this problem is to divide a certain integer n by another integer m until n = 1, obtaining a sequence of numbers. Lets call a[i] each number of this sequence, and let’s say it has k numbers (i.e. you must do k − 1 succesive divisions to reach n = 1). You can only have this sequence if the following restrictions are met:
• a[1] = n, a[i] = a[i − 1] ÷ m, for all 1 < i ≤ k
• a[i] is divisible by m (that is, a[i] mod m = 0) for all 1 ≤ i < k
• a[1] > a[2] > a[3] > . . . > a[k]
    For instance, if n = 125 and m = 5, you have 125, 25, 5 and 1 (you did 3 divisions: 125/5, 25/5 and 5/5). So, k = 4, a[1] = 125, a[2] = 25, a[3] = 5 and a[4] = 1.
    If n = 30 and m = 3, you have 30, 10, 3 and 1. But a[2] = 10, and 10 mod 3 = 1, so there is no sequence because it violates restriction 2. When the sequence doesn’t exist we think it’s not fun and, thus, very boring!
Input
The input will consist on an arbitrary number of lines. Each line will consist of two non-negative integers n, m which are both less than 2000000000. You must read until you reach the end of file.
Output
For each pair n, m you must print the correspondent sequence a (as defined above) in a single line, with each adjacent numbers of the sequence separated by a single space. In the case the sequence doesn’t exist because it violates some restriction, just print the phrase ‘Boring!’ in a single line (without the quotes).
Sample Input
125 5
30 3
80 2
81 3
Sample Output
125 25 5 1
Boring!
Boring!
81 27 9 3 1

问题链接:UVA10190 Divide, But Not Quite Conquer!
问题简述:给定数列的首项和公比的倒数,问该数列的尾项是否为1,如果是则输出数列,否则输出“Boring!”
问题分析:数列问题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA10190 Divide, But Not Quite Conquer! */#include <bits/stdc++.h>using namespace std;int a[100];int main()
{int n, m;while (~scanf("%d%d", &n, &m)) {if (m < 2 || n < m) {printf("Boring!\n");} else {int cnt = 0;while (n % m == 0 && n >= m)a[cnt++] = n, n /= m;a[cnt] = n;if (a[cnt] != 1 || cnt == 0)printf("Boring!\n");else {for (int i = 0; i < cnt; i++)printf("%d ", a[i]);printf("%d\n", a[cnt]);}}}return 0;
}

TLE的C++语言程序如下:

/* UVA10190 Divide, But Not Quite Conquer! */#include <bits/stdc++.h>using namespace std;int main()
{int n, m;while (~scanf("%d%d", &n, &m)) {int a = 1;while (a < n) a *= m;if (a != n)printf("Boring!\n");else {while (n > 1) {printf("%d ", n);n /= m;}printf("%d\n", n);}}return 0;
}

UVA10190 Divide, But Not Quite Conquer!【等差数列】相关推荐

  1. UVa 10190 - Divide, But Not Quite Conquer!

    题目:给你一个等比数列的首项和公比的倒数,如果尾项是1输出这个数列,否则输出Boring!. 分析:数学题.按照题目要求数列是递减的,所以公比的倒数一定要大于1,即m > 1. 然后在附加一个条 ...

  2. python算法书籍-有哪些用 Python 语言讲算法和数据结构的书?

    1.Python数据结构篇 数据结构篇主要是阅读[Problem Solving with Python](Welcome to Problem Solving with Algorithms and ...

  3. 排队论是计算机科学新分支,(计算机科学的分支领域体系.doc

    (计算机科学的分支领域体系 计算机科学的分支领域体系 算法和数据结构 程序设计语言 体系结构 数值和符号计算 操作系统 软件方法学和工程 数据库和信息检索系统 人工智能和机器人学 人机通信 算法和数据 ...

  4. 《Design of Computer Programs》学习笔记(2 - 1)Back of the Envelope - Lesson 2

    Back of the Envelope envelope n.信封(金山词霸) Lesson 2 视频链接: Lesson 2 - Udacity 1. 练习:Zebra Puzzle zebra ...

  5. 商业智能软件在汽车销售中的应用分析

    一 . 引言 在激烈的市场竞争环境中,一个企业如果要生存和发展,就必需了解市场.了解客户树立 "以市场为导向,以客户为中心"的经营理念.汽车销售企业作为服务业尤其如此面对瞬息万变的 ...

  6. python基本原理概论_怎样开始自学Python?

    本人才疏学浅,学识大多浅尝辄止,故文章若有错误,不论是文字笔误还是理解有错,烦请您留言以告知,本人必定感激不尽! **Python分类下的系列文章,不断更新中,如果你迫不及待地想要看看写得如何可以先试 ...

  7. 分治法 分治法求解递推式

    分治法 分治法基本就是下面的三步 分(divide):无法有效解决的划分更小的问题 治(conquer):递归求每一个子问题的解 合(combine):合并解得出原问题解 MergeSort:排列 1 ...

  8. Lecture 3 Divide and Conquer

    1.Divide the problem(instance) into one or more sub-problem; 2.Conquer each sub-problem recursively; ...

  9. 分治法 divide and conquer

    分治算法包含以下步骤: 1.分(divide):将一个大问题分解成若干个子问题,每个子问题的问题规模n更小了,这样就有了好几个待解决的子问题. 2.治(conquer):递归的去解决每个子问题. 3. ...

最新文章

  1. 如何在谷歌云平台上部署可解释性模型
  2. 静态方法和实例化方法的区别
  3. 如何解决ORA-00054资源正忙,要求指定NOWAIT?
  4. mysql和mybatis优化_MySQL + mybatis的SQL优化方案
  5. matlab需要多大运存_提高matlab运行效率
  6. 中国金刚石线行业“十四五规划”与未来产销需求预测报告2021-2027年
  7. redis编译安装:make 的新错误--collect2: ld returned 1 exit status
  8. python使用的一些小事儿
  9. 计算机专业怎样提升竞争力,新形势下如何提高计算机专业学生就业竞争力.doc...
  10. 公司申请了网易企业电子邮箱,用手机端办公方便吗?
  11. Python快速教程 尾声
  12. Vue err:This dependency was not found
  13. golang MySQL 占内存_使用golang插入mysql性能提升經驗
  14. 时间序列-Auto-ARIMA模型
  15. 数字信号处理实验(六)——FIR滤波器的设计
  16. 我是一只IT小小鸟(转载)
  17. 加工中心计算机编程自学,加工中心编程能自学吗?
  18. 数据处理第3部分:选择行的基本和高级的方法
  19. 0002计算机组成原理与体系结构02
  20. 制作在线单词测试的软件,推荐几个在线测试英语单词量的网站

热门文章

  1. mysql——逗号分割字段情况
  2. 地图整饰-框架与格网
  3. php mysql合同跟踪,使用TCP协议进行路由跟踪
  4. vivo手机怎么投屏到电脑_小功能大用处!vivo手机的智慧投屏,轻松实现“跨屏显示”...
  5. 自动化部署mysql主从复制集群_使用docker部署mysql主从复制集群
  6. Qtcreator配置Ros环境
  7. E9流程表单中动态自定义添加button js代码
  8. SpringBoot集成 Shiro
  9. Spring集成Quartz定时任务
  10. 各种存储分配算法java代码实现_Java实现操作系统中四种动态内存分配算法:BF+NF+WF+FF...