当前位置:网站首页>【小码匠自习室】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;
}
边栏推荐
猜你喜欢
基于FPGA的FIR滤波器的实现(1)—采用fir1函数设计
更改C盘用户目录下的用户名(亲测有效)
Flink1.15 组件RPC通信过程概览图
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
暗恋云匹配匿名交友聊天系统开发
非科班毕业生,五面阿里:四轮技术面+HR一面已拿offer
HackTheBox | Horizontall
Experience Sharing | Systematic Design and Development of Business Cache
MySQL:索引(1)原理与底层结构
全网最全的AItium Designer 16下载资源与安装步骤
随机推荐
更改默认打开应用程序设置
flink知识
idea中项目呈现树形结构
win32&mfc————win32菜单栏&库
年初离职,学习半年源码,终于拿到了蚂蚁Offer,分享面试过程
window停掉指定端口的进程
代码随想录笔记_动态规划_322零钱兑换
poj2096 Collecting Bugs
MySQl表的增删查改(CRUD)
webgl 基础
php文件上传下载(存放文件二进制到数据库)
HackTheBox | Previse
从零开始,如何拥有自己的博客网站【华为云至简致远】
Tsinghua | GLM-130B: An Open Bilingual Pre-training Model
腾讯,投了个 “离诺贝尔奖最近的华人”
sample function—R language
医学图像数据增强-归一化
LeetCode简单题之统计星号
基于FPGA的FIR滤波器的实现(1)—采用fir1函数设计
【系统设计】S3 对象存储