题目链接: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. 分享知识-快乐自己:Struts2 (常用的 constant 总结)

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-/ ...

  2. QTableWidget设计原则

    一.组成结构: 列表控件由水平表头(self.horizontalHeader()).垂直表头(self.verticalHeader())和单元格(QTableWidgetItem)组成 其中表头又 ...

  3. 关于python包,模块,.pyc文件和文件导入理解

    参考文献 一.包 包是一个文件夹,用来存放模块和子包. 包里一般会有一个__init__.py的文件(也可以没有). 包里会有一个__pycache__文件夹,存放.py文件经解释器解释后的中间字节码 ...

  4. leetcode 205. Isomorphic Strings(哈希表)

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  5. SQL关联查询中on与where

    微信公众号:刺刺刺猬的优雅 前段时间,做一个查询,打算用left join查询存在于A表但不存在于B表记录,但怎么查都不对,原因是把所有filter全部放在了where语句中,因此回头看了资料,记录一 ...

  6. BZOJ5461: [PKUWC2018]Minimax

    BZOJ5461: [PKUWC2018]Minimax https://lydsy.com/JudgeOnline/problem.php?id=5461 分析: 写出\(dp\)式子:$ f[x] ...

  7. docker 局域网仓库(registry)

    sudo docker pull daocloud.io/registry 安装仓库(registry)  使用daocloud/aliyun镜像吧,官网仓库真心没法用   sudo docker r ...

  8. python中如何定义main方法

    我们有时写的python模块需要自己测试, 简单方法就是定义main函数, 然后测试自己的模块接口. def main():      test_yourCode() if __name__ == & ...

  9. Poj 1504 Adding Reversed Numbers(用字符串反转数字)

    一.题目大意 反转两个数字并相加,所得结果崽反转.反转规则:如果数字后面有0则反转后前面不留0. 二.题解 反转操作利用new StringBuffer(s).reverse().toString() ...

  10. Poj 1125 Stockbroker Grapevine(Floyd算法求结点对的最短路径问题)

    一.Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a ...