提交时间:2022-08-08 11:33:56
运行 ID: 54953
#include <iostream> #include <cmath> #include <cstdio> using namespace std; int main() { // freopen("number.in","r",stdin); // freopen("number.out","w",stdout); int T; cin>>T; for (int i=0;i<T;i++) { int n,p,l; cin>>n>>p; for(l=1;l<=n*p;l++) { int sum=0; for(int a=0;a<=n-1;a++) { sum+=a+l; } if(sum%p==0) { cout<<l<<endl; break; } } if(l>n*p) cout<<-1<<endl; } return 0; }