Logo aaa 的博客

博客

CF1646A

...
aaa
2025-12-01 12:54:09

本文章由 WyOJ Shojo 从洛谷专栏拉取,原发布时间为 2022-03-11 07:51:52

这道题的意思就是对于每一个 $a_{i}$,要么是 $0≤a_i <n$,或者是 $a_i=n^2$,然后给出 $n$ 和 $s$ 代表所有数字之和,求有多少个 $a_i = n^2$。

思路

因为答案在给定的约束下是唯一的,所以我们直接输出 $\lfloor s/n^2 \rfloor$ 就可以了。由于 $n^2$ 可能会爆 int,所以直接输出 $s/n/n$。

代码

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
long long t,n,s;
int main(){
	std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>t;
	while(t--){
		cin>>n>>s;
		if(s==0){\/\/其实不用特判也可以
			cout<<0<<endl;
			continue;
		}
		cout<<s\/n\/n<<endl;
	}
	return 0;
} 

评论

暂无评论

发表评论

可以用@mike来提到mike这个用户,mike会被高亮显示。如果你真的想打“@”这个字符,请用“@@”。