题解:Codeforces Round 962 (Div. 3) D
D. Fun
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output
Counting is Fun!
— satyam343
Given two integers
Note that order matters (e.g. (
给定两个整数
注意顺序问题(例如 (
Input
The first line contains a single integer
Each test case contains two integers
It is guaranteed that the sum of
输入
第一行包含一个整数
每个测试用例包含两个整数
保证所有测试用例的
Output
Output a single integer — the number of triplets (
输出
输出一个整数 -
Example
Input
4 7 4 10 5 7 1000 900000 400000
Output
4 10 7 1768016938
Note
In the first test case, the triplets are (
In the second test case, the triplets are (
注
在第一个测试用例中,三元组是 (
在第二个测试用例中,三元组是 (
题意
题目说得非常直白
给你两个数
使
给出所有的
题解
本题的时间复杂度看似是
因为你只要确定了
那我们只要根据式子,已知
然后对遍历
两者取最小值即可
代码
#include <bits/stdc++.h> #define int long long #define INF 0x3f3f3f3f #define all(x) x.begin(),x.end() using i64 = long long; int t = 1; void solve(){ i64 ans = 0; int n,m; std::cin >> n >> m; for(int i = 1 ; i <= n && i <= m ; i ++) { for(int j = 1 ; i+j <= m && i*j <= n ; j ++) { ans += std::min(m-i-j,(n-i*j)/(i+j)); } } std::cout << ans << "\n"; } signed main(){ std::cin >> t; while(t--){ solve(); } return 0; }
posted on 2024-07-30 10:42 Jiejiejiang 阅读(34) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】