D. Divisible Pairs
#include<bits/stdc++.h>
#define ll long long
#define PII pair<ll,ll>
using namespace std;
const int maxn=2e5+10;
ll a[maxn];
ll work(ll x)
{
ll ret=1;
for(ll i=x;i>=x-1;i--)
{
ret*=1LL*i;
}
return ret/2;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
map<PII,ll>m,vis;
set<PII>s;
int n;
ll x,y;
cin>>n>>x>>y;
for(int i=1;i<=n;i++)
{
cin>>a[i];
ll x1=a[i]%x;
ll y1=a[i]%y;
m[{x1,y1}]++;
s.insert({x1,y1});
}
ll ans=0;
for(auto i:s)
{
if(vis[i]==0)
{
vis[i]=1;
if(i.first==0)
{
ans+=work(m[{0,i.second}]);
}
if(x-i.first==i.first&&m[{i.first,i.second}]==1)
{
continue;
}
else if(x-i.first==i.first)
{
ans+=work(m[{x-i.first,i.second}]);
continue;
}
ans+=1LL*m[{x-i.first,i.second}]*m[{i.first,i.second}];
vis[{x-i.first,i.second}]=1;
}
}
cout<<ans<<'\n';
}
return 0;
}
E. Anna and the Valentine's Day Gift
#include<bits/stdc++.h>
#define ll long long
using namespace std;
//安娜会优先将那些后缀0较多的先反转,以减小长度
//萨沙会优先将那些后缀0较多的数字和后缀0较少(最好没有后缀0)的数字合并
//这个时间复杂度值只允许我们扫描一遍过去
const int maxn=2e5+10;
ll a[maxn],c[maxn];
int work(ll x)//计算x的后缀0个数
{
int cnt=0;
while(x)
{
if(x%10==0)
{
cnt++;
}
else{
break;
}
x/=10;
}
return cnt;
}
ll coun(ll x)//计算x的位数
{
ll cnt=0;
while(x)
{
cnt++;
x/=10;
}
return cnt;
}
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
int t;
cin>>t;
while(t--)
{
int n,m;
ll ans=0;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
ans+=coun(a[i]);
c[i]=work(a[i]);
}
sort(c+1,c+1+n);
for(int i=n;i>=1;i-=2)
{
ans-=c[i];
}
if(ans>m)
{
cout<<"Sasha\n";
}
else{
cout<<"Anna\n";
}
}
return 0;
}