题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010

题意:中文题诶~

思路:求第一个比 x (1<=x<=1e18)大或者等于的数y, 且y的因子只有2, 3, 5,即y=pow(2, i)*pow(3, j)*pow(5, k);

那么显然我们可以通过枚举i, j, k求出所有由2, 3, 5因子构成的数,并将其存入数组中,再二分查找数组中第一个大于等于x的数即为答案;

代码:

 #include <bits/stdc++.h>
#define ll long long
#define MAXN 100000
using namespace std; ll a[MAXN];
const ll inf=1e18; ll get_pow(ll x, int n){
ll ans=;
while(n){
if(n&){
ans*=x;
}
x*=x;
n>>=;
}
return ans;
} void geloutingyu(void){ //**注意不能直接用pow(),会有精度问题
int pos=;
for(ll i=; get_pow(, i)<=inf; i++){
for(ll j=; get_pow(, i)*get_pow(, j)<=inf; j++){
for(ll k=; get_pow(, i)*get_pow(, j)*get_pow(, k)<=inf; k++){
a[pos++]=get_pow(, i)*get_pow(, j)*get_pow(, k);
}
}
}
} int main(void){
int t;
ll x;
geloutingyu();
sort(a, a+MAXN);
cin >> t;
while(t--){
cin >> x;
if(x==){
cout << << endl;
continue;
}
int pos=lower_bound(a, a+MAXN, x)-a;
cout << a[pos] << endl;
}
return ;
}

51nod1010(枚举+二分)的更多相关文章

  1. HDU4430 Yukari's Birthday(枚举+二分)

    Yukari's Birthday  HDU4430 就是枚举+二分: 注意处理怎样判断溢出...(因为题目只要10^12) 先前还以为要用到快速幂和等比数列的快速求和(但肯定会超__int64) 而 ...

  2. CSU OJ PID=1514: Packs 超大背包问题,折半枚举+二分查找。

    1514: Packs Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 61  Solved: 4[Submit][Status][Web Board] ...

  3. 4 Values whose Sum is 0(枚举+二分)

    The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute ...

  4. Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分

    C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is p ...

  5. HDU 4282 A very hard mathematic problem --枚举+二分(或不加)

    题意:问方程X^Z + Y^Z + XYZ = K (X<Y,Z>1)有多少个正整数解 (K<2^31) 解法:看K不大,而且不难看出 Z<=30, X<=sqrt(K) ...

  6. Subset---poj3977(折半枚举+二分查找)

    题目链接:http://poj.org/problem?id=3977 给你n个数,找到一个子集,使得这个子集的和的绝对值是最小的,如果有多种情况,输出子集个数最少的: n<=35,|a[i]| ...

  7. hdu 5288 OO’s Sequence 枚举+二分

    Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...

  8. codeforces 613B B. Skills(枚举+二分+贪心)

    题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  9. Codeforces gym101612 L.Little Difference(枚举+二分)

    传送:http://codeforces.com/gym/101612 题意:给定一个数n(<=1e18),将n分解为若干个数的成绩.要求这些数两两之间的差值不能大于1. 分析: 若n==2^k ...

随机推荐

  1. python3与Redis连接操作

    Python3之redis使用   简介 redis是一个key-value存储系统,和Memcache类似,它支持存储的value类型相对更多,包括string(字符串),list(链表),set( ...

  2. Hibernate学习---第十一节:Hibernate之数据抓取策略&批量抓取

    1.hibernate 也可以通过标准的 SQL 进行查询 (1).将SQL查询写在 java 代码中 /** * 查询所有 */ @Test public void testQuery(){ // ...

  3. linux-常用指令3

    系统管理命令 stat              显示指定文件的详细信息,比ls更详细 who               显示在线登陆用户 whoami          显示当前操作用户 host ...

  4. hdu-5652 India and China Origins(二分+bfs判断连通)

    题目链接: India and China Origins Time Limit: 2000/2000 MS (Java/Others)     Memory Limit: 65536/65536 K ...

  5. [原]NYOJ-216-A problem is easy

    大学生程序代写 /*A problem is easy 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 When Teddy was a child , he was a ...

  6. 作为.NET程序员,您需要IronPython么?

    .NET作为一个成熟的开发平台,为很多语言的发展提供了肥沃的土壤:历史相对久远的有Managed C++.C#.VB.NET.J#,正值壮年的则有IronPython.IronRuby,而老赵极力推崇 ...

  7. UML Design Via Visual Studio-Sequence Diagram

    本文主要介绍在Visual Studio中设计时序图,内容如下: 何时使用时序图 时序图元素介绍 条件.循环在时序图中的使用 直接通过代码生成时序图 一.何时使用时序图 当要查看单个用例内若干对象的行 ...

  8. webpy+nginx+uwsgi安装配置

    转:(1)安装Nginx1.1 下载nginx-1.0.5.tar.gz并解压1.2 ./configure (也可以增加--prefix= path指定安装路径)此时有可能会提示缺少pcre支持,如 ...

  9. Log Structured Merge Trees(LSM) 原理

    http://www.open-open.com/lib/view/open1424916275249.html

  10. uboot和内核分区的修改

    随着内核的更新,内核越来越大,uboot给nand的kernel分区默认是2M的 device nand0 <nandflash0>, # parts = 4  #: name       ...