CodeForces 1992E Novice's Mistake
1.CodeForces 1992E Novice's Mistake
2.CodeForces 1935A Entertainment in MAC3.CodeForces 1992C Gorilla and Permutation4.CodeForces 1992D Test of Love5.CodeForces 1992B Angry Monk6.CodeForces 1992A Only Pluses7.CodeForces 1983B Corner Twist8.CodeForces 1983A Array Divisibility9.CodeForces 1983C Have Your Cake and Eat It Too10.CodeForces 1883B Chemistry11.CodeForces 1883A Morning12.CodeForces 1883C Raspberries13.CodeForces 1883D In Love14.CodeForces 1883E Look Back15.CodeForces 1883F You Are So Beautiful16.CodeForces 1883G1 Dances (Easy version)17.CodeForces 908B New Year and Buggy Bot18.CodeForces 908C New Year and Curling19.CodeForces 1132B Discounts20.CodeForces 1619D New Year's Problem21.Codeforces Round 964 (Div. 4)题目链接:CodeForces 1992E 【Novice's Mistake】
思路
直接对a,b枚举肯定会超时,因为a,b数数字过大,但是通过结果a * n - b可以发现结果最多为6位数,所以对结果的位数进行枚举,然后枚举a,来计算出b并判断是否符合题意,同时需要去掉b不符合题目的范围的情况。
代码
#include <functional> #include <iostream> #include <algorithm> #include <queue> #include <stdio.h> #include <string> #include <cstring> #include <vector> using namespace std; #define ll long long const int N = 50090 + 10; struct ab { ll a, b; } res[N]; void solve(){ ll n, a, b, ans = 1; cin >> n; string s1 = to_string(n); for (int i = 2; i <= 10000; i++) { string s2 = ""; while (s2.length() <= 10) s2 += s1; for (int j = 1; j <= 6; j++) { ll b = s1.size() * i - j; if (b < 1 || b > min(10000ll, n * i)) continue; if (to_string(i * n - b) == s2.substr(0, j)) { res[ans++] = {i, b}; } } } cout << ans - 1 << endl; for (int i = 1; i < ans; i++) { cout << res[i].a << " " << res[i].b << endl; } } int main() { int t; cin >> t; while (t--) { solve(); } return 0; }
合集:
Codeforces
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】