称号:发现没有比给定数量少n的。只要2,3一个因素的数字组成。

分析:数论。贪婪,分而治之。

用两个三分球,分别代表乘法2,和繁殖3队列,队列产生的数字,原来{1}。

然后。每取两个指针相应元素*2和*3的值中最小的即为未找到的数字中最小的;

注意,可能生成反复数据。不要存进去(反复数据。一定连续产生)。

说明:打表计算。二分查询输出就可以。

#include <iostream>
#include <cstdlib>
#include <cstdio> using namespace std; int next[330]; int bs(int key, int r)
{
int l = 0,m;
while (l < r) {
m = (l+r)/2;
if (next[m] < key)
l = m+1;
else r = m;
}
return r;
} int main()
{
int two = 0,three = 0,count = 0;
next[0] = 1;
while (next[count] > next[count-1]) {
if (next[two]*2 < next[three]*3)
next[++ count] = next[two ++]*2;
else {
if (next[three]*3 == next[two]*2) two ++;
next[++ count] = next[three ++]*3;
}
} int n;
while (cin >> n && n)
cout << next[bs(n, count)] << endl; return 0;
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

UVa 11621 - Small Factors的更多相关文章

  1. uva 129 krypton factors ——yhx

     Krypton Factor  You have been employed by the organisers of a Super Krypton Factor Contest in which ...

  2. UVa 884 - Factorial Factors

    题目:输出n!中素数因数的个数. 分析:数论.这里使用欧拉筛法计算素数,在计算过程中求解就可以. 传统筛法是利用每一个素数,筛掉自己的整数倍: 欧拉筛法是利用当前计算出的全部素数,乘以当前数字筛数: ...

  3. UVA 10699 Count the factors 题解

    Time limit 3000 ms OS Linux Write a program, that computes the number of different prime factors in ...

  4. UVA 160 - Factors and Factorials

     Factors and Factorials  The factorial of a number N (written N!) is defined as the product of all t ...

  5. UVA 1575 Factors

    https://vjudge.net/problem/UVA-1575 题意: 令f(k)=n 表示 有n种方式,可以把正整数k表示成几个数的乘积的形式. 例 10=2*5=5*2,所以f(10)=2 ...

  6. UVa 10299 - Relatives

    题目大意:Euler's Totient的应用. 几乎和UVa 10179 - Irreducable Basic Fractions一样,于是偷了个懒,直接用10179题的代码,结果WA了,感觉一样 ...

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

  8. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  9. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

随机推荐

  1. 《Effective C++ 》学习笔记——条款02

    ****************************  一. Accustoming Yourself to C++ **************************** 条款02: Pref ...

  2. 怎样将android studio项目导入eclipse

    如今,越来越多的开源项目都是用android studio来开发的,所以源码都与eclipse有所不同. 以下是将android studio项目导入eclipse的一般步骤: 1. 先解压项目: 2 ...

  3. hdu 4961 Boring Sum(数学题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4961 Problem Description Number theory is interesting ...

  4. POJ 3181 Dollar Dayz 简单DP

    这DP虽然简单 但是思考一下还是挺好的 题意是 1,2,3,4....k 用加法凑成N 每个数可取不限个数 令dp[i][j] 表示前i种数凑成j的方案数 然后dp[i][j] = dp[i - 1] ...

  5. [POJ 3150] Cellular Automaton (矩阵高速幂 + 矩阵乘法优化)

    Cellular Automaton Time Limit: 12000MS   Memory Limit: 65536K Total Submissions: 3048   Accepted: 12 ...

  6. Android该HTTP下载

    今天学习了Android开发中比較难的一个环节,就是断点续传下载,非常多人看到这个标题就感觉头大.的确,假设没有良好的逻辑思维,这块的确非常难搞明确.以下我就将自己学到的知识和一些见解写下供那些在这个 ...

  7. android中listview分页载入数据

    前段时间做的新浪微博项目一直想实现listview分页载入数据,今天最终实现了,哈哈!感觉挺好的,今天又写了个demo给大家分享下. 首先说下listview的优化方案,这也是面试中常考的题目.优化方 ...

  8. 【Android】应用启动画面

    几乎所有的Android应用程序都会有一个启动画面,展示自己的LOGO,本版信息,或者更人性化一点的,在很长的加载信息中,变换一些显示的文字等,让无聊的等待时间添加点调味剂. 具体实现来说,应该创建一 ...

  9. java 配置及安装Eclipse

    jdk下载 点我~ Java SE Development Kit 8u20 You must accept the Oracle Binary Code License Agreement for ...

  10. Moran’s I空间统计中出现内存溢出的问题

    在经济学.资源管理.生物地理学.政治地理学和人口统计等领域,经常会有如下的研究需求: 研究区域中的富裕区和贫困区之间的最清晰边界在哪里? 研究区域中存在可以找到异常消费模式的位置吗? 研究区域中意想不 ...