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;
long long a[1000],i,n,j;
bool kt;
int main()
{
freopen("nguyento.inp","r",stdin);
freopen("nguyento.out","w",stdout);
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++)
if (a[i]>1)
{
kt=true;
for (j=2; j*j<=a[i]; j++)
if (a[i]%j==0) kt=false;
if (kt==true) cout<<a[i]<<" ";
}
return 0;
}
const fi='xsum1.inp';
fo='xsum1.out';
var f1,f2:text;
a:array[1..20000]of integer;
i,n,j,x,dem,k,m,t:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n,x);
for i:=1 to n do
read(f1,a[i]);
dem:=0;
for i:=1 to n do
for j:=1 to n do
begin
for k:=1 to n do
if (i<j) and (j<k) then
begin
t:=0;
for m:=i to k do
t:=t+a[m];
if t=x then inc(dem);
end;
end;
for i:=1 to n do
if x=a[i] then inc(dem);
writeln(f2,dem);
close(f1);
close(f2);
end.
program COST;
var n,m,s,dem:int64;a:
array[1..1000000] of int64;
i,j:longint;
begin
readln(n,m);
for i := 1 to n do read(a[i]);
dem := 0;
for i := 1 to n do
begin
s := 0;
for j := i to n do
begin
s := s+a[j];
if s <= m then
begin
inc(dem);
continue;
end
else if a[j] > m then break;
end;
end;
write(dem);
end.
program du_lieu;
uses crt;
var i,n:integer;
a:array[1..100]of integer;
tbc:real;
f:text;
begin
clrscr;
assign(f,'DULIEU.INP');reset(f);
readln(f,n);
for i:=1 to n do
begin
read(f,a[i]);
end;
close(f);
for i:=1 to n do
tbc:=tbc+a[i];
writeln(tbc/n);
readln;
end.
Bài 1:
const fi='b5.inp.txt';
fo='b5.out.txt';
var f1,f2:text;
a:array[1..255]of integer;
i,n,kt,j,dem:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do
read(f1,a[i]);
dem:=0;
max:=1;
for i:=1 to n do
if a[i]>1 then
begin
kt:=0;
for j:=2 to trunc(sqrt(a[i])) do
if a[i] mod j=0 then kt:=1;
if kt=0 then
begin
inc(dem);
if max<a[i] then max:=a[i];
end;
end;
writeln(f2,dem);
if dem=0 then writeln(f2,'Khong co so nguyen to trong day')
else writeln(f2,max);
close(f1);
close(f2);
end.
#include <bits/stdc++.h>
using namespace std;
long long n,i,j,dem;
bool kt;
int main()
{
freopen("dnto.inp","r",stdin);
freopen("dnto.out","w",stdout);
cin>>n;
for (i=2; i<=n; i++)
{
kt=true;
for (j=2; j*j<=i; j++)
if (i%j==0) kt=false;
if (kt==true) dem++;
}
cout<<dem;
return 0;
}
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
const ll maxn = 1e7+4;
const int m=1e9+7;
int n,a[15],x[100],kt=-1;
int check(int n)
{
if(n<2) return 0;
for(int i=2;i<=sqrt(n);i++) if(n%i==0) return 0;
return 1;
}
void Try(int i,int sum)
{
if(i==n)
{
if(check(sum))
{
cout<<sum<<"\n";
kt=1;
}
return;
}
for(int t=1;t<=n;t++)
{
if(x[a[t]]==0)
{
x[a[t]]=1;
Try(i+1,sum*10+a[t]);
x[a[t]]=0;
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
freopen("GHEPSO.INP","r",stdin);
freopen("GHEPSO.OUT","w",stdout);
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+1+n);
Try(0,0);
if(kt==-1) cout<<"-1\n";
}
code đệ quy - quay lui đây nhé bạn