当前位置:网站首页>[Small Coder Study Room] ABC179-C: It is a miracle that the code does not count down
[Small Coder Study Room] ABC179-C: It is a miracle that the code does not count down
2022-08-08 14:01:00 【Small yards artisan】
碎碎念
- 说真的,When I submitted it, I felt a little nervous in my heart,However, my execution time is high1957msIt's a miracle that the code of 's code is not ranked last……
题目地址
- C - A x B + C
- https://atcoder.jp/contests/abc179/tasks/abc179_c
题目描述
给一个正整数N,满足A \times B + C = N的(A,B,C) How many pairs of data are there?
约束条件
- 2 \leq N \leq 10^6
- All values are integers.
输入
输入一个正整数
N
输出
The output meets the number of submissions
示例输入 1
3
示例输出 1
3
满足条件的 A \timesB + C = 3: (A, B, C) = (1, 1, 2), (1, 2, 1), (2, 1, 1).
示例输入 2
100
示例输出 2
473
示例输入 3
1000000
示例输出 3
13969985
题解
Small Coder Problem Solving One
- 先看执行结果
- 再看代码
- 从1Start enumerating how many pairs of factor pairs there are for each value,就是固定c
- Adding the logarithms of each value is the answer
- very violent solution,Don't study(* ̄︶ ̄)
void coder_solution() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
long long ans = 0;
for (int i = 1; i < n; ++i) {
for(int j = 1; j * j <= i; ++j) {
if (i % j == 0) {
if (i / j == j) {
ans++;
} else {
ans += 2;
}
}
}
}
cout << ans;
}
参考题解
- 思路:固定a,枚举b的可能性,c随b变化,-1是因为要保证c至少为1
#include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
cin >> N;
long long res = 0;
for (long long a = 1; a < N; ++a) res += (N - 1)/ a;
cout << res << endl;
}
参考题解2
- 思路:暂时没看懂
#include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
cin >> N;
long long res = 0;
for (long long A = 1; A * A < N; ++A) ++res;
for (long long A = 1; A * A < N; ++A) {
long long num = max((N - 1) / A - A, 0LL);
res += num * 2;
}
cout << res << endl;
}
边栏推荐
猜你喜欢
随机推荐
华谊“在劫难逃”,4年亏掉64亿
String转成double等类型注意非空判断
Verilog HDL Bits training 09 grammar foundation
【索引】图神经论文之GCN(持更)
无头单向非循环链表(C语言实现)
如何对用户输入进行校验
「复盘」面试BAMT回来整理398道高频面试题,助你拿高薪offer
清华|GLM-130B:一个开放的双语预训练模型
设计一个跨平台的即时通讯系统(采用华为云ECS服务器作为服务端 )【华为云至简致远】
一文搞懂│XSS攻击、SQL注入、CSRF攻击、DDOS攻击、DNS劫持
看三年的CRUD程序员如何解决数据库死锁的
PC端实用软件推荐
R语言ggplot2可视化:使用ggpubr包的ggtexttable函数可视化表格数据(直接绘制表格图或者在图像中添加表格数据)、使用tab_add_hline函数为表头添加横线并自定义线条宽度
R语言patchwork包将多个ggplot2可视化结果组合起来、使用plot_annotation函数以及tag_level参数为组合图添加自定义编码序列(字符向量列表)
专访|360高瀚昭:ISC十年,360数字安全大脑能够“看见”什么?
MySQL:锁机制 |表级锁、行级锁 | 排它锁、共享锁 | 间隙锁
serialize serialize native method
Time to update your tech arsenal in 2020: Asgi vs Wsgi (FastAPI vs Flask)
路由器——交换机——网络交换机:区别
6. [opencv mouse callback event]