51Nod 1010 只包含因子2 3 5的数
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000)
第2 - T + 1行:每行1个数N(1 <= N <= 10^18)
共T行,每行1个数,输出>= n的最小的只包含因子2 3 5的数。
5
1
8
13
35
77
2
8
15
36
80
开始直接暴力试了一波,TLE。后面一想似乎可以先打表,再二分查找。打表还是一个技术活。
//Asimple
#include <bits/stdc++.h>
#define swap(a,b,t) t = a, a = b, b = t
#define CLS(a, v) memset(a, v, sizeof(a))
#define debug(a) cout << #a << " = " << a <<endl
#define test() cout<<"=========="<<endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int maxn = +;
ll n, m, res, ans, len, T, k, num, sum, t;
ll a[maxn]; void init(){
ll er, san, wu;
er = san = wu = ;
a[] = ;
len = ;
while( a[len]<=1e18 ) {
a[++len] = min(*a[er], min(*a[san], *a[wu]));
if( a[len]==*a[er] ) er ++;
if( a[len]==*a[san] ) san ++;
if( a[len]==*a[wu] ) wu ++;
}
} ll b_search(ll low, ll high, ll num){
while( low<high ) {
ll mid = (low+high)/;
if( a[mid]==num ) return num;
else if(a[mid]<num ) low = mid+;
else high = mid;
}
return a[low];
} void input() {
ios_base::sync_with_stdio(false);
init();
cin >> T;
while( T -- ) {
cin >> n;
ans = b_search(, len, n);
cout << ans << endl;
}
} int main(){
input();
return ;
}
51Nod 1010 只包含因子2 3 5的数的更多相关文章
- 51nod 1010 只包含因子2 3 5的数 二分答案
1010 只包含因子2 3 5的数 K的因子中只包含2 3 5.满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15. 所有这样的K组成了一个序列S,现在给出一个数n,求S中 > ...
- 51nod 1010 只包含因子2 3 5的数 打表
只包含因子2 3 5的数 题目连接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010 Description K的 ...
- 51Nod 1010 只包含因子2 3 5的数 Label:None
K的因子中只包含2 3 5.满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15. 所有这样的K组成了一个序列S,现在给出一个数n,求S中 >= 给定数的最小的数. 例如:n = ...
- 51Nod 1010 只包含因子2 3 5的数(打表+二分)
K的因子中只包含2 3 5.满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15. 所有这样的K组成了一个序列S,现在给出一个数n,求S中 >= 给定数的最小的数. 例如:n = ...
- 51nod 1010 只包含因子2 3 5的数 && poj - 1338 Ugly Numbers(打表)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010 http://poj.org/problem?id=1338 首先 ...
- 51Nod 1010 只包含因子2 3 5的数 | 预处理+二分
Input示例 5 1 8 13 35 77 Output示例 2 8 15 36 80 分析:将所有的只含有2 3 5因子的数打一个表保存在一个数组里,然后二分查找第一个>=数组里的数,输出 ...
- 1007 正整数分组 1010 只包含因子2 3 5的数 1014 X^2 Mod P 1024 矩阵中不重复的元素 1031 骨牌覆盖
1007 正整数分组 将一堆正整数分为2组,要求2组的和相差最小. 例如:1 2 3 4 5,将1 2 4分为1组,3 5分为1组,两组和相差1,是所有方案中相差最少的. Input 第1行:一个 ...
- 只包含因子2 3 5的数(51NOD 1010)
K的因子中只包含2 3 5.满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15. 所有这样的K组成了一个序列S,现在给出一个数n,求S中 >= 给定数的最小的数. 例如:n = ...
- 把只包含因子2、3和5的数称作丑数(Ugly Number)。例如6、8都是丑数,但14不是,因为它包含因子7。 习惯上我们把1当做是第一个丑数。求按从小到大的顺序的第N个丑数。
// ConsoleApplication1.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> ...
随机推荐
- PHP memcached memcache 扩展安装
好久没配置环境今天安装PHP 开发环境, 项目比较老,一开始以为项目用的是memcache 装完后发现 项目用的是memcached 所以正好两个都装了. 碰到些坑希望能帮助到百度到这篇文章的伙伴 . ...
- react 使用 react-loadable分包
文档 yarn add react-loadable 使用 import Loadable from "@/components/loadable"; const Home = L ...
- Coffee and Coursework (Hard Version)
Coffee and Coursework (Hard Version) time limit per test 2.5 seconds memory limit per test 256 megab ...
- Git查看两个版本之间修改了哪些文件
gdiff 63e3b647d55fcc643e793e650c893be8601719b1 548cdaf01dbc2f08d1ca0b697a24afe512b75a2f --stat git l ...
- Oracle ROWNUM用法和分页查询总结
**************************************************************************************************** ...
- linux出现tmp空间满的情况解决
cd命令tab补全的时候报错: cd /ro-bash: cannot create temp file for here-document: No space left on device-bash ...
- darknet集成遇到的问题以及解决方法
将darknet集成进工程时,遇到了一些问题,下面记录一下解决方法: 集成步骤: 首先在yolo编译的时候,需要将三个开关打开: #define GPU#define CUDNN#define OPE ...
- java框架之SpringBoot(3)-日志
市面上的日志框架 日志抽象层 日志实现 JCL(Jakarta Commons Logging).SLF4J(Simple Logging Facade For Java).JBoss-Logging ...
- python框架之Flask(5)-@app.before_request原理
示例 from flask import Flask app = Flask(__name__) @app.before_request def xx(): pass @app.route('/') ...
- python基础之 编码进阶,文件操作和深浅copy
1.编码的进阶 字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要以unicode作为中间编码.即先将其他编码的字符串解码(decode)成unicode,再从unic ...