题目链接: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. Raft 为什么是更易理解的分布式一致性算法——(1)Leader在时,由Leader向Follower同步日志 (2)Leader挂掉了,选一个新Leader,Leader选举算法。

    转自:http://www.cnblogs.com/mindwind/p/5231986.html Raft 协议的易理解性描述 虽然 Raft 的论文比 Paxos 简单版论文还容易读了,但论文依然 ...

  2. Selenium-浮层的操作

    实现-百度登录浮层-输入登录用户名 #! /usr/bin/env python #coding=utf-8 ''' 百度首页-登录浮层 ''' from selenium import webdri ...

  3. js string.format 方法

    String.prototype.format = function(args) { var result = this; if (arguments.length > 0) { if (arg ...

  4. Convolutional Neural Networks for Visual Recognition 3

    Gradient Computing 前面我们介绍过分类器模型一般包含两大部分,一部分是score function,将输入的原始数据映射到每一类的score,另外一个重要组成部分是loss func ...

  5. Java中String和byte[]间的 转换

    数据库的字段中使用了blob类型时,在entity中此字段可以对应为byte[] 类型,保存到数据库中时需要把传入的参数转为byte[]类型,读取的时候再通过将byte[]类型转换为String类型. ...

  6. shell ## %% 使用说明

    path='apps/home/usr/app/test.txt' a=${path##*/} b=${path#*/} c=${path%%/*} d=${path%/*}············· ...

  7. flume入门之一:flume 安装及测试

    http://flume.apache.org/ flume下载:http://mirror.bit.edu.cn/apache/flume/1.7.0/apache-flume-1.7.0-bin. ...

  8. 二 lambda表达式

    1:lambda写的好可以极大的减少代码冗余,同时可读性也好过冗长的内部类,匿名类. 2: lambda表达式配合Java8新特性Stream API可以将业务功能通过函数式编程简洁的实现. 3: l ...

  9. windows 创建和调用 动态库,静态库

    windows创建和调用静态库 // MathFuncsLib.h namespace MathFuncs { class MyMathFuncs { public: // Returns a + b ...

  10. js检测对象属性

    In:(检测自身及原型属性) var o={x:1}; "x" in o; //true,自有属性存在 "y" in o; //false "toSt ...