因子问题 I - Ugly Numbers
题目:
Ugly numbers are numbers whose only prime factors are 2, 3 or 5
. The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ... shows the first 11 ugly numbers. By convention, 1 is included.
Write a program to find and print the 1500’th ugly number.
Input
There is no input to this program.
Output
Output should consist of a single line as shown below, with ‘’ replaced by the number computed. Sample Output The 1500'th ugly number is .
AC代码:
#include <iostream>
using namespace std;
int min1 (int a,int b)
{return a<b?a:b;}//自定义函数
int main()
{
long long a[1500];
a[0] = 1;
long long a2=0,a3=0,a5=0;
for(int i=1;i<1500;i++)
{
while(a[a2]*2<=a[i-1]) a2++;
while(a[a3]*3<=a[i-1]) a3++;
while(a[a5]*5<=a[i-1]) a5++;
a[i]= min1(min1(a[a2]*2,a[a3]*3),a[a5]*5);
}
cout<<"The 1500'th ugly number is "<<a[1499]<<'.'<<endl;
}
做此类数学题一定要冷静啊!
不要首先想着捷径,一定要先想正轨,更容易解出来
因子问题 I - Ugly Numbers的更多相关文章
- 丑数(Ugly Numbers, UVa 136)
丑数(Ugly Numbers, UVa 136) 题目描述 我们把只包含因子2.3和5的数称作丑数(Ugly Number).求按从小到大的顺序的第1500个丑数.例如6.8都是丑数,但14不是,因 ...
- UVA - 136 Ugly Numbers (有关set使用的一道题)
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5, 6, 8, 9, ...
- [POJ1338]Ugly Numbers
[POJ1338]Ugly Numbers 试题描述 Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequ ...
- Ugly Numbers
Ugly Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21918 Accepted: 9788 Descrip ...
- poj 1338 Ugly Numbers(丑数模拟)
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063? viewmode=contents 题目链接:id=1338&q ...
- leetcode@ [263/264] Ugly Numbers & Ugly Number II
https://leetcode.com/problems/ugly-number/ Write a program to check whether a given number is an ugl ...
- Geeks Interview Question: Ugly Numbers
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5, 6, 8, 9, ...
- 136 - Ugly Numbers
Ugly Numbers Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3 ...
- Ugly Numbers(STL应用)
题目链接:http://poj.org/problem?id=1338 Ugly Numbers Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
随机推荐
- bzoj1202: [HNOI2005]狡猾的商人(差分约束)
1202: [HNOI2005]狡猾的商人 题目:传送门 题解: 据说是带权并查集!蒟蒻不会啊!!! 可是听说lxj大佬用差分约束A了,于是开始一通乱搞. 设s[i]为前i个月的总收益,那么很容易就可 ...
- zzulioj--1791-- 旋转矩阵(模拟水题)
旋转矩阵 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 268 Solved: 116 SubmitStatusWeb Board Descr ...
- [jzoj 5930] [NOIP2018模拟10.26】山花 解题报告 (质因数分类)
题目链接: http://172.16.0.132/senior/#contest/show/2538/2 题目: 小S决定从某一个节点$u$开始对其子树中与$u$距离小于$K$的节点代表的花树进行采 ...
- C++线程传参数
struct TThreadParam { LPVOID pThis; int visionIndex; }; class CMilTestDlg : public CDialog { // Cons ...
- Kali linux 2016.2(Rolling)中的payloads模块详解
不多说,直接上干货! 前期博客 Kali linux 2016.2(Rolling)中的Exploits模块详解 payloads模块,也就是shellcode,就是在漏洞利用成功后所要做的事情.在M ...
- 【算法】prim算法(最小生成树)(与Dijkstra算法的比较)
最小生成树: 生成树的定义:给定一个无向图,如果它的某个子图中任意两个顶点都互相连通并且是一棵树,那么这棵树就叫做生成树.(Spanning Tree) 最小生成树的定义:在生成树的基础上,如果边上有 ...
- BootStrap学习(二)——重写首页之topbar
1.布局容器 帮助文档:http://v3.bootcss.com/css/#overview-container BootStrap需要为页面内容和栅栏系统包裹一个.container容器.提供的两 ...
- Ubuntu系统下Import cv2提示no modules ...错误
最近利用pycharm在Ubuntu系统下调试一个Python项目,将pycharm的解释器从python2.7更换到python3.4后,程序中的Import cv2提示no modules nam ...
- 安卓怎么不如ios运行流畅
一.优先级别不同:iOS最先响应屏幕当我们使用iOS或者是Android手机时,第一步就是滑屏解锁找到相应程序点击进入.而这个时候往往是所有操控开始的第一步骤,iOS系统产品就表现出来了流畅的一面,但 ...
- C# 将string 转换为二维码图片,然后转为base64字符串编码 。
需在nuget 添加此dll ///content字符串 public static string GetQRCode(string content, int moduleSize = 9) { va ...