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;
}

The Bells are Ringing(枚举)的更多相关文章

  1. UVA - 12119 The Bells are Ringing (枚举)

    Perhaps you all have heard the mythical story about Tower of Hanoi (The details of this story is not ...

  2. The Bells are Ringing UVALive - 4060(枚举求解)

    输出整数N,使得  t1 <= N  统计有多少组t1,t2,t3,满足:1<t1<t2<t3<=1000000,t3-t1<=25,且t1,t2,t3的最小公倍数 ...

  3. .Uva&LA部分题目代码

    1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...

  4. [学习笔记] 舞蹈链(DLX)入门

    "在一个全集\(X\)中若干子集的集合为\(S\),精确覆盖(\(\boldsymbol{Exact~Cover}\))是指,\(S\)的子集\(S*\),满足\(X\)中的每一个元素在\( ...

  5. Nordic Collegiate Programming Contest 2015​ B. Bell Ringing

    Method ringing is used to ring bells in churches, particularly in England. Suppose there are 6 bells ...

  6. Swift enum(枚举)使用范例

    //: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...

  7. 编写高质量代码:改善Java程序的151个建议(第6章:枚举和注解___建议88~92)

    建议88:用枚举实现工厂方法模式更简洁 工厂方法模式(Factory Method Pattern)是" 创建对象的接口,让子类决定实例化哪一个类,并使一个类的实例化延迟到其它子类" ...

  8. Objective-C枚举的几种定义方式与使用

    假设我们需要表示网络连接状态,可以用下列枚举表示: enum CSConnectionState { CSConnectionStateDisconnected, CSConnectionStateC ...

  9. Help Hanzo (素数筛+区间枚举)

    Help Hanzo 题意:求a~b间素数个数(1 ≤ a ≤ b < 231, b - a ≤ 100000).     (全题在文末) 题解: a~b枚举必定TLE,普通打表MLE,真是头疼 ...

随机推荐

  1. Luogu P3619 魔法 【贪心/微扰证明】

    题目描述 cjwssb知道是误会之后,跟你道了歉.你为了逗笑他,准备和他一起开始魔法.不过你的时间不多了,但是更惨的是你还需要完成n个魔法任务.假设你当前的时间为T,每个任务需要有一定的限制ti表示只 ...

  2. jsp标准标签库——jstl

    JSP标准标签库(JSTL)是一个JSP标签集合,它封装了JSP应用的通用核心功能. JSTL支持通用的.结构化的任务,比如迭代,条件判断,XML文档操作,国际化标签,SQL标签. 除了这些,它还提供 ...

  3. B Balala Power!

    Bryce1010模板 每个字母所在位置对应权值加和,肯定存不下. 但我们只需要26个字母对应值之间的关系即可,开一个数组a[i][j]分别记录字母i在j这个位置上出现了多少次,对于大于26的值进位, ...

  4. 转-MAC 下安装PHONEGAP开发环境

    来自:http://jinzhe.net/post/8.html 什么是Phonegap呢?Phonegap是一个利用HTML5去开发App的框架.可以为安卓.iOS.WP.黑莓.火狐等移动操作系统. ...

  5. poj1781In Danger(约瑟夫) 问题

    链接 之前队内赛中的一道题目 当时怎么想也没想到,就一直放到了今天,刚才看另一题的讲解突然看到时拿这个题作为引子来讲的,就仔细看了下. 参考<<具体数学>> p7. Josep ...

  6. ASP.NET MVC+Bootstrap个人博客之修复UEditor编辑时Bug(四)

    我的个人博客站在使用百度富文本编辑器UEditor修改文章时,遇到了一些问题,(不知是bug,还是我没有配置好).但总算找到了解决方法,在此记录下来. 遇到的问题: 正常来讲,进入文章修改页,只需将U ...

  7. CF915C Permute Digits

    思路: 从左到右贪心放置数字,要注意判断这个数字能否放置在当前位. 实现: #include <bits/stdc++.h> using namespace std; typedef lo ...

  8. 微信小程序组件解读和分析:十四、slider滑动选择器

    slider滑动选择器组件说明: 滑动选择器. slider滑动选择器示例代码运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? 01 02 03 04 05 06 07 08 ...

  9. greendao3.2.3配置时遇到的问题

    这两天我一直在研究greendao这个框架,我在GitHub下载了 greendao3.2.2:https://github.com/greenrobot/greenDAO,照着网址里面来配置: // ...

  10. android中使用图文并茂的按钮

    代码: <LinearLayout android:orientation="horizontal" android:layout_width="match_par ...