A. Greatest Convex【Codeforces Round #842 (Div. 2)】
A. Greatest Convex
You are given an integer
†
‡ If
Input
The first line contains a single integer
The only line of each test case contains a single integer
Output
For each test case output a single integer — the largest possible integer
If no such
Example
input
4
3
6
8
10
output
2
5
7
9
Note
In the first test case,
In the third test case,
简述题意
给出
思路
- 由于
的范围是 ,因此不能直接枚举求阶乘 - 观察example的input和output数据的特性我们可以猜测总是存在最大的
使得 满足条件 - 当
时 总是满足是k的倍数
代码
点击查看代码
#include<iostream>
using namespace std;
int k,t;
int main(){
cin >> t;
while(t -- ){
cin >> k;
cout << k - 1 << endl;
}
}
解题历程
- 错误方向浪费大量时间:多种方式求阶乘,分解质因数,二分搜索
- Runtime error on pretest 2(218 ms,262100 KB) 【00:19】//阶乘
- Wrong answer on pretest 1(0 ms,3900 KB) 【00:45】 //分解质因数
- Compilation error(0 ms,0 KB) 【00:55】 //看出规律,蒙出答案k-1
- AC(46 ms,0 KB) 【00:57】
经验总结
- 仔细思考数据范围与关系式的关系
- 签到题就会有签到题的样子:代码量小,如果代码量大了一个认真分析是否方向错误
- 可以看排名中的ac时间确定题目的难易
- 注意对已知关系式的进一步解析
- Codeforces:†, ‡, §, ¶分别代表1,2,3,4,一般是对题目信息的补充
原因
- 不熟悉codeforces
- 手疏
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】