HDU 5878 I Count Two Three 青岛网络赛
来源:互联网 发布:下载个淘宝买东西的 编辑:程序博客网 时间:2024/05/17 04:44
题意找出大于等于 n 的最小的 能表示为 2的a次 乘以 3的b次 乘以 5的c次 乘以 7的d次 的数。
n最大为1e9,符合条件的数也没几个,预处理出来,排个序,二分一下就好了。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <set>#include <map>#include <cmath>#include <cstdlib>#include <stack>#include <queue>using namespace std;typedef long long LL;const LL MAX = 1000000000;LL ans[20000];int cnt = 0;LL Power(LL a, LL b){LL ans = 1;while (b > 0){if (b&1)ans *= a;b >>= 1;a *= a;}return ans;}void init(){LL tmp;for(int a = 0; a <= 31; a++){for(int b = 0; b <= 19; b++){for(int c = 0; c <= 12; c++){for(int d = 0; d <= 11; d ++){tmp = Power(2, a)*Power(3, b);if(tmp > MAX) break;tmp *= Power(5, c);if(tmp > MAX) break;tmp *= Power(7, d);if(tmp > MAX) break;ans[++cnt] = tmp;}}}}}int bisearch(int x){if(x == 1) return 1;int l = 1, r = cnt + 1, m;while(l < r){m = (l + r) >> 1;if(ans[m] > x) r = m;else if(ans[m] == x) return ans[m];else l = m + 1;}return ans[l];}int main(){init();sort(ans + 1, ans + 1 + cnt);int T;scanf("%d", &T);while(T--){int tmp;scanf("%d", &tmp);printf("%d\n", bisearch(tmp));} return 0;}
0 0
- HDU 5878 I Count Two Three 青岛网络赛
- HDU 5878 I Count Two Three 2016青岛网赛
- HDU 5878 I Count Two Three(2016亚洲区青岛站网络赛)
- hdu 5878 I Count Two Three ICPC青岛站网络赛1001
- hdu 5878 I Count Two Three 2016ACM/ICPC青岛赛区网络赛1001
- hdu5878 I Count Two Three -ICPC网络赛青岛赛区
- 2016 ACM/ICPC 青岛区域赛网络赛 1001 I Count Two Three(打表+二分)
- 2016 ACM/ICPC 青岛赛区网络赛 I Count Two Three
- 青岛网赛1001 HDU5878 I Count Two Three
- HDOJ 5878 I Count Two Three 【2016青岛网赛】暴力打表+二分枚举
- hdu 5878 I Count Two Three
- 【30.53%】【hdu 5878】I Count Two Three
- HDU 5878 I Count Two Three .
- HDU 5878 - I Count Two Three
- HDU 5878 I Count Two Three
- HDU-5878-I Count Two Three
- 2016青岛online——I count two three
- 5878 I Count Two Three
- Mvp+Rxandroid+Retrofit的简单实现
- 机器学习系列(11)_Python中Gradient Boosting Machine(GBM)调参方法详解
- bzoj 4448: [Scoi2015]情报传递 (树上主席树)
- lintcode寻找旋转排序数组中的最小值/循环有序数组的查找
- Github建立自己的项目-简要教程
- HDU 5878 I Count Two Three 青岛网络赛
- Hadoop(09) 序列化
- Java 并发编程_Volatile
- JVM垃圾收集器
- Matlab基本操作0
- c#@屏@蔽@窗@口@关@闭@按@钮
- 使用myeclipse自带spring3.1和hibernate4框架applicationContext.xml报错解决方法
- 遭遇fastjson的一个坑
- 【C语言】输出好看的星星图形