Perhaps you all have heard the mythical story about Tower of Hanoi (The details of this story is not required to solve this problem): “There is a tower of Hanoi with 64 disks and three pegs and the preists make one move everyday and the earth will be destroyed when all the pegs have been moved from one peg to the other following the rules of Tower of Hanoi.” In this problem we deal with a similar story – The story of an ancient temple. The ancient temple has three incredibly large bells. At the beginning of time the three bells rang together. Then the three bells never rang together and when they will ring together again the earth will be destroyed. The three bells have cycle length of t1, t2 and t3 (Here t1<t2<t3 and all are expressed in miliseconds). By this I mean that the first bell rings at every t1 seconds from the beginning, the second bell rings at every t2 second from the beginning and the third bell rings at every t3 second from the beginning. Also note that the difference of the values of t1, t2 and t3 is not that much different so that ordinary people think many time that they are ringing together.

Given the time difference between destruction of earth and beginning of time you will have to find the values of t1, t2 and t3.

Input

The input file contains at most 600 lines of inputs. Each line contains an integer which denotes (in millisecond) the time difference between the beginning of time and the time of the bells ringing together. Input is terminated by a line containing a single zero. All the input numbers will fit in a 64 bit signed integer.

Output

For each line of input produce two lines or more of output. The first line contains the serial of output. Each of the next lines contains three integers which denote the values of t1, t2 and t3 respectively. The value of t1, t2 and t3 is such that t1<t2<t3 and 0<t1, t2, t3≤1000000 and |t1-t3|≤25. If you cannot find values of t1, t2, twith such constraints then print the line “Such bells don’t exist” instead. In case there is more than one solution sort the output in ascending order of the value of t1, then (in case of a tie) in the ascending order of the value of t2 and then (still a tie) in ascending order of the value t3. Print a blank line after the output for each test case. Look at the output for sample input for details.

Sample Input                           Output for Sample Input

10 
103 
0 
                      

Scenario 1:

1 2 5

1 2 10

1 5 10

2 5 10

 

Scenario 2:

Such bells don't exist

 

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long ll;
using namespace std;
const int maxn = ; ll gcd(ll a, ll b) {
return b== ? a : gcd(b, a%b);
} int main() {
ll lcm;
int cas = ;
while (scanf("%lld", &lcm) != EOF && lcm) {
printf("Scenario %d:\n", cas++);
int flag = ;
for (ll i = ; i <= maxn && i <= lcm; i++) {
if (lcm % i)
continue;
for (ll j = i+; j-i <= ; j++) {
if (lcm % j)
continue;
ll tmp = (i * j) / gcd(i, j);
for (ll k = j+; k-i <= && k <= maxn; k++) {
if (lcm % k)
continue;
ll ans = (tmp * k) / gcd(tmp, k);
if (ans == lcm) {
printf("%lld %lld %lld\n", i, j, k);
flag = ;
}
}
}
}
if (!flag)
printf("Such bells don't exist\n");
printf("\n");
}
return ;
}

最新文章

  1. Linux 通过sendmail 发邮件到外部邮箱
  2. unity-点乘和叉乘的应用
  3. 《Kotli&#173;n for &#173;androi&#173;d Deve&#173;lopers&#173;》中文翻译
  4. C++基础知识(2)---函数
  5. 传递引用类型参数的两种方式(转自 MSDN)
  6. 20141017--类型String类
  7. Android常用的工具类(转)
  8. Windows Server 2008 R2 开启Win7主题效果Aero
  9. 利用Apperance协议定义View的全局外观
  10. fzu 1909 An Equation(水题)
  11. 001-centos6.5下安装jenkins
  12. web roadmap
  13. &lt;转&gt;vmp3.0.9全保护拆分解析
  14. 使用kill -9 进程ID杀死jps中进程
  15. 客户端代码压缩成zip和服务器开启gzip
  16. POJ1144 Network(割点)题解
  17. Oracle保存带&amp;的数据
  18. HTTP协议详解之URL篇
  19. 基于Redis的消息队列php-resque
  20. T-SQL 重复读(Double Read)问题的理解

热门文章

  1. android 4.2 root
  2. Linux 特殊符号使用: 倒引号`的使用
  3. zk create() 方法
  4. 举例android项目中的string.xml出现这个The character reference must end with the &#39;;&#39; delimiter.错误提示的原因及解决办法
  5. JQuery - 改变css样式
  6. [转]apache下htaccess不起作用,linux,windows详解
  7. android 小结
  8. 怎样在android实现uc和墨迹天气那样的左右拖动效果
  9. 主题:Java WebService 简单实例
  10. OC中多线程的一些概念