Bài 1:
#include<bits/stdc++.h>
#define FI(n,nn) for(int i=n;i<nn;i++)
#define FJ(m,mm) for(int j=m;j<mm;j++)
#define cl(n) cout<<n<<endl
#define c_(n) cout<<n<<" ";
#define name "BROTHERNUM"
#define f first
#define s second
#define pb push_back
#define ph push
#define ll long long
#define INF 200005
#define db double
#define ud unsigned
#define End "\n"
#define _ " "
using namespace std;
int T,N,M;
int t_uoc(int n){
int sum=0;
for(int i=2;i<=sqrt(n);i++){
if(n%i==0){
sum+=i;
if(i!=n/i) sum+=n/i;
}
}
return sum;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
freopen(name".INP","r",stdin);
freopen(name".OUT","w",stdout);
cin>>T;
FI(1,T+1){
cin>>M>>N;
if(t_uoc(M)==t_uoc(N))
cout<<"YES"<<End;
else
cout<<"NO"<<End;
}
return 0;
}
Bài 2:
#include<bits/stdc++.h>
#define FI(n,nn) for(int i=n;i<nn;i++)
#define FJ(m,mm) for(int j=m;j<mm;j++)
#define cl(n) cout<<n<<endl
#define c_(n) cout<<n<<" ";
#define name "COUNTCHAR"
#define f first
#define s second
#define pb push_back
#define ph push
#define ll long long
#define INF 200005
#define db double
#define ud unsigned
#define End "\n"
#define _ " "
using namespace std;
string s; vector<int> vt;
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
freopen(name".INP","r",stdin);
freopen(name".OUT","w",stdout);
cin>>s;
FI(0,s.size()){
if(s[i]>='0' && s[i]<='9'){
vt.pb(s[i]-'0');
}
}
sort(vt.begin(),vt.end(),greater<>());
cout<<vt.size()<<End;
for(auto x : vt) cout<<x;
return 0;
}
Bài 3:
#include<bits/stdc++.h>
#define FI(n,nn) for(int i=n;i<nn;i++)
#define FJ(m,mm) for(int j=m;j<mm;j++)
#define cl(n) cout<<n<<endl
#define c_(n) cout<<n<<" ";
#define name "KPRIME"
#define f first
#define s second
#define pb push_back
#define ph push
#define ll long long
#define INF 200005
#define db double
#define ud unsigned
#define End "\n"
#define _ " "
using namespace std;
int n,k,a[100005]; bool kt[1000006]; vector<int> vt;
void snt(int n){
kt[0]=kt[1]=true;
for(int i=2;i*i<=n;i++){
for(int j=i*2;j*j<=n;j+=i){
kt[j]=true;
}
}
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
freopen(name".INP","r",stdin);
freopen(name".OUT","w",stdout);
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i];
int i=0; snt(1000000);
while(k!=0){
i++;
if(!kt[a[i]]){
vt.pb(a[i]);
k--;
}
}
sort(vt.begin(),vt.end());
for(auto x : vt) cout<<x<<" ";
return 0;
}