Poj 1338 Ugly Numbers(数学推导)
一、题目大意
本题要求写出前1500个仅能被2,3,5整除的数。
二、题解
三、java代码
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n;
int i2_mul;
int i3_mul;
int i5_mul;
long[] ugly=new long[1501];
i2_mul = 1;
i3_mul = 1;
i5_mul = 1;
ugly[1]=1;
for( int i = 2; i <= 1500; i++ ){
ugly[i] = Math.min(ugly[i2_mul]*2,Math.min(ugly[i3_mul]*3,ugly[i5_mul]*5));
if(ugly[i] == ugly[i2_mul]*2 )
i2_mul++;
if(ugly[i] == ugly[i3_mul]*3 )
i3_mul++;
if(ugly[i] == ugly[i5_mul]*5)
i5_mul++;
}
while((n=sc.nextInt())!=0){
System.out.println(ugly[n]);
}
}
}
Poj 1338 Ugly Numbers(数学推导)的更多相关文章
- poj 1338 Ugly Numbers(丑数模拟)
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063? viewmode=contents 题目链接:id=1338&q ...
- poj 1338 Ugly Numbers
原题链接:http://poj.org/problem?id=1338 优先队列的应用,如下: #include<cstdio> #include<cstdlib> #incl ...
- 51nod 1010 只包含因子2 3 5的数 && poj - 1338 Ugly Numbers(打表)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010 http://poj.org/problem?id=1338 首先 ...
- POJ 3252 Round Numbers 数学题解
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...
- poj 3252 Round Numbers 【推导·排列组合】
以sample为例子 [2,12]区间的RoundNumbers(简称RN)个数:Rn[2,12]=Rn[0,12]-Rn[0,1] 即:Rn[start,finish]=Rn[0,finish]-R ...
- Poj 2247 Humble Numbers(求只能被2,3,5, 7 整除的数)
一.题目大意 本题要求写出前5482个仅能被2,3,5, 7 整除的数. 二.题解 这道题从本质上和Poj 1338 Ugly Numbers(数学推导)是一样的原理,只需要在原来的基础上加上7的运算 ...
- Ugly Numbers(STL应用)
题目链接:http://poj.org/problem?id=1338 Ugly Numbers Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
- [ACM训练] 算法初级 之 数据结构 之 栈stack+队列queue (基础+进阶+POJ 1338+2442+1442)
再次面对像栈和队列这样的相当基础的数据结构的学习,应该从多个方面,多维度去学习. 首先,这两个数据结构都是比较常用的,在标准库中都有对应的结构能够直接使用,所以第一个阶段应该是先学习直接来使用,下一个 ...
- 递推(三):POJ中的三道递推例题POJ 1664、POJ 2247和POJ 1338
[例9]放苹果(POJ 1664) Description 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法. In ...
随机推荐
- 栈 堆 stack heap
点餐 做菜 Stack and Heap 堆和栈的区别 - Grandyang - 博客园 https://www.cnblogs.com/grandyang/p/4933011.html 在和计算机 ...
- Mac下nginx安装和配置
nginx安装 brew search nginx brew install nginx 安装完以后,可以在终端输出的信息里看到一些配置路径: /usr/local/etc/nginx/nginx.c ...
- 转。git 乌龟的使用安装
TortoiseGit 简称 tgit, 中文名海龟Git. 海龟Git只支持神器 Windows 系统, 有一个前辈海龟SVN, TortoiseSVN和TortoiseGit都是非常优秀的开源的版 ...
- 搜索ABAP程序代码中的字符串
标准程序名:RPR_ABAP_SOURCE_SCAN /BEV1/NERM07DOCS
- 从硬盘设计思想到RAID改良之道
监控硬盘的前生今世关于桌面硬盘.企业级近线硬盘(NL-SAS/SATA)和监控硬盘的差别,我们在前文中已经讲得很详细,这里再换一个角度来看看. "监控硬盘是希捷和西数为视频监控定制的,典型的 ...
- 人生要golang
第一篇 : 初识golang 第二篇 : 下载及安装 未完待续 ............................................
- Yii2 关于电子商务的开源项目
https://github.com/samdark/yii2-shop https://github.com/omnilight/yii2-shopping-cart https://github. ...
- 每天一个Linux命令(7)pwd命令
pwd命令以绝对路径的方式显示用户当前工作目录.命令将当前目录的全路径名称(从根目录)写入标准输出.全部目录使用/分隔.第一个/表示根目录,最后一个目录是当前目录. (1)用法介绍: pwd[ ...
- Data Structure Array: Find the two numbers with odd occurrences in an unsorted array
http://www.geeksforgeeks.org/find-the-two-numbers-with-odd-occurences-in-an-unsorted-array/ #include ...
- [算法]找到无序数组中最小的K个数
题目: 给定一个无序的整型数组arr,找到其中最小的k个数. 方法一: 将数组排序,排序后的数组的前k个数就是最小的k个数. 时间复杂度:O(nlogn) 方法二: 时间复杂度:O(nlogk) 维护 ...