#include <iostream>
using namespace std;
int main() {
long long n, l, r;
cin >> n >> l >> r;
if ((l % n + (r - l)) >= n) {
cout << n - 1 << endl;
} else {
cout << max(l % n, r % n) << endl;
}
return 0;
}
问题: code::blacks调试代码时,默认是不能查看STL数据结构得值,只能看到内存地址,调试起来会很不爽
现象:
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
void coder_solution();
int main() {
// 小码匠
coder_solution();
return 0;
}
bool is_prime(long long x) {
if (x < 2) {
return false;
}
for (long long i = 2; i * i <= x; i++) {
if (x % i == 0) {
return false;
}
}
return true;
}
void coder_solution() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// 输入
long long n;
cin >> n;
vector<long long> vi;
int loop_count = cbrt(n);
vector<bool> tf(1000001, true);
tf[0] = false;
tf[1] = false;
vi.push_back(2);
for (int i = 3; i <= loop_count; i += 2) {
if (tf[i]) {
for (int j = 3; j * i <= loop_count; j += 2) {
tf[j * i] = false;
}
vi.push_back(i);
}
}
int len = vi.size();
int ans = 0;
for (int i = 0; i < len - 1; ++i) {
for (int j = i + 1; vi[j] * vi[j] * vi[j] <= n / vi[i] && j < len; ++j) {
ans++;
}
}
cout << ans;
}
调试时
解决办法:启用gdb来调试
Step1: 确认gdb可执行文件路径
gdb执行文件在安装code::blacks的MinGW\bin下面
Step2:命令中启动gdb,如下图,执行命令
D:\>cd \tools\CodeBlocks\MinGW\bin
D:\tools\CodeBlocks\MinGW\bin>dir gdb*
驱动器 D 中的卷没有标签。
卷的序列号是 B84A-DA49
D:\tools\CodeBlocks\MinGW\bin 的目录
2018/05/12 15:28 59,605 gdb.exe
2018/05/12 15:28 9,594,561 gdborig.exe
2018/05/12 15:28 506,436 gdbserver.exe
3 个文件 10,160,602 字节
0 个目录 153,524,097,024 可用字节
D:\tools\CodeBlocks\MinGW\bin>gdb
GNU gdb (GDB) 8.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-w64-mingw32".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb)
Step3: 点击菜单栏【Settings】,点击【Debugger...】选项
点击左侧【GDB/CDB debugger】的 【Default】选项,去掉【Disable startup scripts(-nx)(GDB only)】
如下图,勾选掉后,按【OK】按钮,完成设置
继续调试,调试窗口可以看到vector值
END