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>
#include<algorithm>
using namespace std;
const int maxN = 1e4 + 1;
int n, k, arr[maxN];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for(int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
cout << arr[k - 1];
}
Input:
7 4
29 847 1928 45 298 918219 38129
Output: 847
uses crt;
var f,g:text;
n,i,m,k,j:integer;
a:array[1..10000] of integer;
const fi='BAI2.INP'; fo='BAI2.OUT';
begin
assign(f,fi); reset(f);
assign(g,fo); rewrite(g);
readln(f,n);
for i:=1 to n do
readln(f,a[i]);
for i:=1 to n do
begin
m:=a[i];
for j:=i+1 to n do
if odd(m+a[j])=false then k:=k+1;
end;
write(g,k);
close(f);
close(g);
end.
#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 <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 i,n,x,a[1000],dem;
int main()
{
cin>>n;
for (i=1; i<=n; i++)
{
cin>>a[i];
}
dem=0;
for (i=1; i<=n; i++)
if (a[i]%2==0) dem++;
cout<<dem<<endl;
for (i=1; i<=n; i++)
if (a[i]%2==0) cout<<a[i]<<" ";
return 0;
return 0;
}
#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;
}