怎么做,求大佬qwq
查看原帖
怎么做,求大佬qwq
1016748
Wangyuqi2010楼主2024/10/13 12:18

贴50pts暴力

有没有O(1)的办法

#include<iostream>
#define ll long long
using namespace std;
ll n,k,q,r;
int main() {
	int T;
	cin>>T;
	while(T--) {
		ll ans=0;
		cin>>n>>k;
		if(k==0){
			cout<<1<<endl;
			continue;
		}
		for(q=1; q<=n/k+1; q++) {
			r=n-q*k;
			if(r>=0&&n/q==k&&n%q==r) {
				ans++;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
2024/10/13 12:18
加载中...