貌似这套题【East Central North America 1999, Practice】没有提示数据范围而且数据都是很大的
读入n会爆long long 和 int 所以WA了一次
#include <bits/stdc++.h>
using namespace std;
void Gao(int b)
{
string a;
int sum1=0,sum2=0;
cin>>a;
for (int i=a.length()-1;i>=0;i--)
{
sum2+=pow(b,a.length()-i-1)*(a[i]-'0');
sum1+=a[i]-'0';
}
if (sum2%sum1==0)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
int main()
{
// freopen("a.in","r",stdin);
int T;
bool fst=false;
cin>>T;
while (T--)
{
if (fst) cout<<endl;
fst=true;
int n,b;
while (cin>>b &&b)
Gao(b);
}
return 0;
}