51nod 1010 stl/数论/二分
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010
基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题
![](http://file.51nod.com/images/icon/star.png)
![](http://file.51nod.com/images/icon/plus.png)
K的因子中只包含2 3 5。满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15。
所有这样的K组成了一个序列S,现在给出一个数n,求S中 >= 给定数的最小的数。
例如:n = 13,S中 >= 13的最小的数是15,所以输出15。
Input
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000) 第2 - T + 1行:每行1个数N(1 <= N <= 10^18)
Output
共T行,每行1个数,输出>= n的最小的只包含因子2 3 5的数。
Input示例
5 1 8 13 35 77
Output示例
2 8 15 36 80
这个就是筛丑数把,可以用stl里的容器操作,要筛10915个出来就好了一个也不能少不然会WA的,紫书例题。
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<queue> 5 #include<set> 6 #include<ctime> 7 #include<functional> 8 #include<algorithm> 9 using namespace std; 10 #define LL long long 11 LL num[5] = { 2,3,5 }; 12 priority_queue<LL, vector<LL>, greater<LL> >q; 13 set<LL>s; 14 int main() 15 { 16 q.push(1); 17 s.insert(1); 18 bool ok = 1; 19 int sum = 0; 20 while (sum<=10915) { 21 LL u = q.top();q.pop(); 22 for (int i = 0;i < 3;++i) { 23 LL x = u*num[i]; 24 if (x<0 || x>1e18) { continue; } 25 if (!s.count(x)) { sum++;s.insert(x);q.push(x); } 26 } 27 } 28 LL T, N; 29 s.erase(1); 30 cin >> T; 31 while (T--) { 32 scanf("%lld", &N); 33 printf("%lld\n", *s.lower_bound(N)); 34 } 35 //system("pause"); 36 return 0; 37 }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
· .NET 适配 HarmonyOS 进展
· 用 DeepSeek 给对象做个网站,她一定感动坏了
· DeepSeek+PageAssist实现本地大模型联网
· 手把手教你更优雅的享受 DeepSeek
· Java轻量级代码工程
· 从 14 秒到 1 秒:MySQL DDL 性能优化实战