Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.
#include <bits/stdc++.h>
using namespace std;
unsigned long long a[1000],i,n,uc;
//chuongtrinhcon
unsigned long long ucln(long long a,long long b)
{
if (b==0) return(a);
else return(ucln(b,a%b));
}
//chuongtrinhchinh
int main()
{
freopen("sn3.inp","r",stdin);
freopen("uc.out","w",stdout);
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
uc=ucln(a[1],a[2]);
for (i=3; i<=n; i++)
uc=ucln(uc,a[i]);
cout<<uc;
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n,k;
cin >> n >> k;
int a[n];
for (int i=0;i<n;i++)
cin >> a[i];
sort(a,a+n);
cout << a[k-1];
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll,ll> mp;
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
freopen("MAP1.INP","r",stdin);
freopen("MAP1.OUT","w",stdout);
ll n; cin >> n;
ll a[n+5];
for(ll i=1;i<=n;i++) cin >> a[i], mp[a[i]]++;
for(pair<ll,ll> it:mp) cout << it.first << " " << it.second << "\n";
}
Chúc bạn học tốt!
Uses crt;
var i,n,uoc,j,tam:longint;
Begin
clrscr;
readln(n);uoc:=0;tam:=0;
for i:= 1 to n do if n mod i = 0 then inc(uoc);
if uoc = 2 then write(n,' la so nguyen to')
else for i:= 2 to n do if n mod i = 0 then
begin
tam:=0;
for j:= 1 to i do if i mod j = 0 then inc(tam);
if tam = 2 then write(i,' ');
end;
readln;
end.
Có chỗ nào sai thì bảo mình
#include <iostream>
#include <vector>
using namespace std;
vector<int> primeFactors(int n) {
vector<int> factors;
for (int i = 2; i * i <= n; i++) {
while (n % i == 0) {
factors.push_back(i);
n /= i;
}
}
if (n > 1) factors.push_back(n);
return factors;
}
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> factors = primeFactors(k);
int sum = accumulate(a.begin(), a.end(), 0);
vector<vector<bool>> dp(n+1, vector<bool>(sum+1, false));
dp[0][0] = true;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= sum; ++j) {
dp[i][j] = dp[i-1][j];
if (j >= a[i-1]) {
for (int factor : factors) {
if (a[i-1] % factor == 0) {
dp[i][j] = dp[i][j] || dp[i-1][j-a[i-1]];
break;
}
}
}
}
}
for (int j = 0; j <= sum; ++j) {
if (dp[n][j]) {
cout << j << endl;
break;
}
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long a[1000006];
long long n;
int main()
{
for(int i=1;i<=1000006;i++){
a[i]=i*i;
}
cin>>n;
for(int i=1;i<=n;i++){
if(a[i]%n==0){cout<<a[i]/n;break;}
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long n,dem,i;
int main()
{
freopen("bl1.inp","r",stdin);
freopen("bl1.out","w",stdout);
cin >> n;
for( i = 2; i <= n; i++)
{
dem = 0;
while(n % i == 0)
{
++dem;
n=n/i;
}
if(dem)
{
cout<<i;
if (dem>1) cout <<"^"<<dem;
if (n>i){
cout <<" * ";
}
}
}
return 0;
}