当前位置:网站首页>【小码匠自习室】ABC180-C: 马虎是小孩的天性吗?
【小码匠自习室】ABC180-C: 马虎是小孩的天性吗?
2022-08-08 13:52:00 【小码匠】
碎碎念
- 我肯定是和符号有什么不解之缘吧……
- 这一回我又双叒叕搞错符号啦!(实际就是没把平方数考虑进去,没加等号,然后就WA了……)
- 性能比较:注意数据结构的使用 ABC180-C-01
- 28ms: 参考题解用动态数组vector存储结果,之后在排序
- 19ms:直接用set存储结果
标签
- 数学、分解因数
题目地址
- C - Cream puff
- https://atcoder.jp/contests/abc180/tasks/abc180_c
题目描述
我们有 N 个奶油泡芙.
找出所有可能的人数,我们可以将奶油泡芙均匀地分配给他们而不切割它们。
Constraints
- 1 \leq N \leq 10^{12}
- N is an integer.
输入
Input is given from Standard Input in the following format:
N
输出
Print the numbers of people in ascending order, each in its own line.
输入示例 1
6
输出示例 1
1
2
3
6
例如,我们可以将奶油泡芙平均分配给两个人,每人分三个
示例输入 2
720
示例输出 2
1
2
3
4
5
6
8
9
10
12
15
16
18
20
24
30
36
40
45
48
60
72
80
90
120
144
180
240
360
720
示例输入 3
1000000007
示例输出 3
1
1000000007
题解
小码匠题解
void coder_solution() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
long long n;
cin >> n;
set<long long> a;
for(long long i = 1; i * i <= n; ++i) {
if (n % i == 0) {
a.insert(i);
a.insert(n / i);
}
}
for(auto p : a) {
cout << p << endl;
}
}
参考题解
#include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
cin >> N;
vector<long long> res;
for (long long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
if (i * i != N) res.push_back(N / i);
}
}
sort(res.begin(), res.end());
for (auto v : res) cout << v << endl;
}
边栏推荐
猜你喜欢
自动当道,效率至上 | 快来解锁财务共享服务中心数字化秘籍
Review: What is the pre-approval of autumn recruitment?What is an ordinary autumn move?It's all recruitment, why do you need to set these two recruitment time periods?
[Redis] Redis installation and use of client redis-cli (batch operation)
【系统设计】S3 对象存储
【黑马早报】巴菲特罕见巨亏近3000亿;周鸿祎回应360不能卸载;三亚倡议酒店不变相提高房价;首个国产抗新冠口服药定价不超300元...
从零开始,如何拥有自己的博客网站【华为云至简致远】
【软考 系统架构设计师】软件架构设计⑥ 软件产品线
【个人总结】2022.8.7周结
浅学一下二叉树链式存储结构的遍历
MapStruct入门使用
随机推荐
textarea disable drag and drop
sample function—R language
用 Antlr 重构脚本解释器
Experience Sharing | Systematic Design and Development of Business Cache
「复盘」面试BAMT回来整理398道高频面试题,助你拿高薪offer
KD-SCFNet: More Accurate and Efficient Salient Object Detection Through Knowledge Distillation (ECCV2022)
【Redis】位图以及位图的使用场景(统计在线人数和用户在线状态)
教学习编程,第一步解决自信问题,培养自己的专注力
非科班毕业生,五面阿里:四轮技术面+HR一面已拿offer
flink知识
Prometheus监控Harbor(二进制版)
树上距离为1子集修改
OpenInfra Days China 2022 |StreamNative 翟佳、刘德志受邀分享
R语言使用位置索引筛选dataframe的数据列:筛选单个数据列、筛选多个数据列、列表表达式方法、矩阵式下标方法
Thesis understanding: "Self-adaptive loss balanced Physics-informed neural networks"
mysql 查询一个字段为特定值,并且另一个字段的值出现两次的记录?
使用.NET简单实现一个Redis的高性能克隆版(三)
win32&mfc————win32菜单栏&库
Full of dry goods, Yu Jingxin class of the Institute of Information Technology, Chinese Academy of Sciences will help you get academic research and thesis writing skills
难产的“第一股”:中式快餐之困