【Educational Codeforces Round 17 A题】有所不同的大暴力
来源:互联网 发布:淘宝注册还要拨打号码 编辑:程序博客网 时间:2024/06/12 00:45
题目要求n的第k小的约数。
于是就爆搜嘛。
#include <cstdio>#include <cmath>//#include <iostream>using namespace std;//const long long MAXN = 1e9;//long long a[MAXN];long long n;int cnt = 0;int main(){ int k; cin >> n >> k; for (long long i = 1; i <= n; i++) { if (n % i == 0) { cnt++; if (cnt == k) { cout << i << endl; return 0; } } } printf("-1\n"); return 0;}
这是一开始写的代码,在第5个点T了。。。。
后来其他题都不会,就又写了一份
#include <cstdio>#include <vector>#include <algorithm>#include <iostream>#include <cmath>#include <cstring>using namespace std;//bool is[1e15 + 2];vector<long long> a;int main(){ //memset(is, true, sizeof(is)); long long n; int k; cin >> n >> k; for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { a.push_back(i); a.push_back(n / i); } } sort(a.begin(), a.end()); if (k > (int)a.size()) { printf("-1\n"); } else { cout << a[k - 1] << endl; } return 0;}
遍历到它的一半,还用vector【注意vector的sort,之前我还不是很会用】。这次A了,算是有点技巧吧。。。(:з」∠)
之前还想到了用类似埃筛的思想,找到第一个不是它的约数的数,把那个数的倍数全都设成不是它的约数,但是我埃筛。。。。不怎么会写啊。。。欧拉筛我也不怎么会写qnq 就没写。
这个要下次好好看看把它写熟练啊。
0 0
- 【Educational Codeforces Round 17 A题】有所不同的大暴力
- Educational Codeforces Round 28 A. Curriculum Vitae(读懂题意后的暴力水题)
- Educational Codeforces Round 17 A+B
- Educational Codeforces Round 5 A
- Educational Codeforces Round 20 A
- Educational Codeforces Round 21 A
- Educational Codeforces Round 23 A
- Educational Codeforces Round 17
- Educational Codeforces Round 17
- Educational Codeforces Round 27 A B 暴力+贪心 C 贪心+排序
- codeforces Educational Codeforces Round 21 A
- Educational Codeforces Round 17-A k-th divisor
- Educational Codeforces Round 16 E 题 Generate a String
- Educational Codeforces Round 25 A Binary Protocol 基础题
- Educational Codeforces Round 4 A题 (python进行字符串的划分)
- Educational Codeforces Round 17 题解
- Educational Codeforces Round 1 A. Tricky Sum
- Educational Codeforces Round 1 (A)模拟
- weex项目实战篇(二)
- Leetcode——61. Rotate List
- Loser,除了努力你还会什么?
- codeforce-762-B USB vs. PS/2(贪心)
- 文章标题
- 【Educational Codeforces Round 17 A题】有所不同的大暴力
- 编程珠玑:第10章 节省空间 10.1 稀疏矩阵表示 ---- 解题总结
- VS2015编译Teamtalk的Windows客户端
- 八、java包与修饰符
- HDU 1272 小希的迷宫
- 【BZOJ 1251】序列终结者
- [乐意黎]phpQuery采集微信公众号文章乱码
- 云服务器环境部署到安装Wordpress
- Pseudoprime numbers POJ - 3641