Description

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, t2and 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 t2second 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.

这道题使用枚举的方法就好,不过值得注意的是数据类型的选取,n有可能是一个非常大的数,所以必须把所有整型换成long long型

#include"iostream"
using namespace std;
const int maxn=1000000;
long long gcd(long long a,long long b) //求公共质因数
{
return (b==0)?a:gcd(b,a%b);
} int main()
{
long long n,gonbei1,gonbei2,f=0;
while(cin>>n&&n)
{
int flag=0;
cout<<"Scenario "<<++f<<":"<<endl;
for(long long i=1;i<=1000000;i++)
{
if(n%i) continue;
for(long long j=i+1;j<=i+25&&j<=maxn;j++)
{
if(n%j) continue;
gonbei1=(i*j)/gcd(i,j);
for(long long k=j+1;k<=i+25&&k<=maxn;k++)
{
if(n%k) continue;
gonbei2=(gonbei1*k)/gcd(gonbei1,k);
if(gonbei2==n) {cout<<i<<' '<<j<<' '<<k<<endl;flag=1;}
}
}
}
if(flag==0) cout<<"Such bells don't exist"<<endl;
cout<<endl;
}
return 0;
}

最新文章

  1. Linear Algebra lecture7 note
  2. SEO初级优化--HTML、CSS、JS
  3. Ubuntu下编译SuiteSparse-4.4.1和METIS-4.0.3
  4. 爱情之路(codevs 2070)
  5. jQuery 写的插件图片上下切换幻灯效果
  6. Introduction to Machine Learning
  7. Android 常用时间格式转换代码
  8. 一些dos命令
  9. UVA 10594-Date Flow(无向图的最小费用网络流+题目给的数据有误)
  10. iOS基础 - 多媒体
  11. 一种新的隐藏-显示模式诞生——css3的scale(0)到scale(1)
  12. 警惕一大波银行类木马正在靠近,新型BankBot木马解析
  13. linux 添加ssh和开启ssh服务apt管理的ubuntu
  14. C#_IO操作_查询指定文件夹下的每个子文件夹占空间的大小
  15. jstl select &lt;c:if test下拉菜单不能被选中!
  16. git提交代码到码云详解
  17. redis内部数据结构深入浅出
  18. 基于xtrabackup GDIT方式不锁库作主从同步(主主同步同理,反向及可)
  19. QQ gtk,bkn算法
  20. 20155315 2016-2017-2 《Java程序设计》第七周学习总结

热门文章

  1. [BZOJ1381]Knights
  2. Oracle查询使用空间比较大的前15个表
  3. C#中的预编译指令介绍[转]
  4. 关于jquery获取单选框value属性值为on的问题
  5. 轻松搞懂Java中的自旋锁
  6. AJPFX关于抽象方法和接口
  7. [SPOJ1812]Longest Common Substring II 后缀自动机 多个串的最长公共子串
  8. npm run dev报错--Error: Cannot find module &#39;yargs-parser&#39;
  9. iOS游戏开发之UIDynamic
  10. 【C++】模板简述(四):模板为什么不支持分离编译?