Đếm số nguyên tố trong dãy:
Cho dãy gồm N (0<N< 10^6) số a1, a2, a3, ….,aN; (0<ai<10^9).
Hãy đếm số lượng các số nguyên tố có trong dãy số trên.
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.
Program HOC24;
var d,i,n: integer;
a: array[1..1000] of integer;
t: longint;
function nt(x: longint): boolean;
var j: longint;
begin
nt:=true;
if (x=2) or (x=3) then exit;
nt:=false;
if (x=1) or (x mod 2=0) or (x mod 3=0) then exit;
j:=5;
while j<=trunc(sqrt(x)) do
begin
if (x mod j=0) or (x mod (j+2)=0) then exit;
j:=j+6;
end;
nt:=true;
end;
begin
write('Nhap N: '); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
d:=0; t:=0;
for i:=1 to n do
if nt(a[i]) then
begin
d:=d+1;
t:=t+a[i];
end;
writeln('Co ',d,' so nguyen to trong day');
write('Tong cac so nguyen to trong day la: ',t);
readln
end.
uses crt;
var a:array[1..1000]of integer;
i,n,dem,t,j,kt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
t:=0;
for i:=1 to n do
if a[i]>1 then
begin
kt:=0;
for j:=2 to a[i]-1 do
if a[i] mod j=0 then kt:=1;
if kt=0 then
begin
inc(dem);
t:=t+a[i];
end;
end;
writeln('So luong so nguyen to la: ',dem);
writeln('Tong cac so nguyen to la: ',t);
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n,tc,tl,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
tc:=0;
tl:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then tc:=tc+a[i]
else tl:=tl+a[i];
end;
writeln('Tong cac so chan la: ',tc);
writeln('Tong cac so le la: ',tl);
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln('Tong cua day so la: ',t);
readln;
end.
uses crt;
var a:array[1..1000]of integer;
i,n,dem1,dem2,t1,dem3,j,kt:integer;
begin
clrscr;
readln(n);
for i:=1 to n do
readln(a[i]);
dem1:=0;
dem2:=0;
t1:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then
begin
dem1:=dem1+1;
t1:=t1+a[i];
end;
else dem2:=dem2+1;
end;
dem3:=0;
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 dem3:=dem3+1;
end;
writeln(dem1, ' ',dem2);
writeln(t1);
writeln(dem3);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long x,i,n,nn;
int main()
{
cin>>n;
int dem=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x==0) dem++;
}
cout<<dem;
return 0;
}
uses crt;
var i,n,x,dem,t,kt,j:integer;
a:array[1..100]of integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
dem:=0;
t:=0;
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
begin
kt:=1;
end;
if kt=0 then
begin
dem:=dem+1;
t:=t+a[i];
end;
end;
writeln(dem);
writeln(t);
readln;
end.
#include <iostream>
#include <map>
using namespace std;
int main() {
int n;
cin >> n;
map<int, int> count;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
count[x]++;
}
int ans = 0;
for (auto p : count) {
int x = p.second;
ans += (x * (x - 1)) / 2;
}
cout << ans;
return 0;
}
const fi='dl.pas';
fo='qk.pas';
var f1,f2:text;
i,n,dem,t,dem1,dem2,kt,j:integer;
a:array[1..100]of 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;
for i:=1 to n do
if (a[i] mod 2<>0) and (a[i] mod 7=0) then inc(dem);
t:=0;
for i:=1 to n do
if (10<=a[i]) and (a[i]<=30) then t:=t+a[i];
dem1:=0;
for i:=1 to n do
if (a[i]<0) and (a[i] mod 2<>0) then inc(dem1);
dem2:=0;
for i:=1 to n do
if a[i]>1 then
begin
kt:=0;
for j:=2 to a[i]-1 do
if a[i] mod j=0 then kt:=1;
if kt=0 then inc(dem2);
end;
writeln(f2,'So phan tu le chia het cho 7 la: ',dem);
writeln(f2,'Tong cac phan tu thuoc [10,30] la: ',t);
writeln(f2,'So cac phan tu am le la: ',dem1);
writeln(f2,'So phan tu la so nguyen to la: ',dem2);
close(f1);
close(f2);
end.
#include <bits/stdc++.h>
using namespace std;
long long n,i,x,dem;
int main()
{
cin>>n;
dem=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x==50) dem++;
}
cout<<dem;
return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
bool isPrime(int number) {
if (number < 2) {
return false;
}
for (int i = 2; i <= sqrt(number); i++) {
if (number % i == 0) {
return false;
}
}
return true;
}
int main() {
int N;
cin >> N;
int count = 0;
for (int i = 0; i < N; i++) {
int num;
cin >> num;
if (isPrime(num)) {
count++;
}
}
cout << "Số lượng số nguyên tố trong dãy là: " << count << endl;
return 0;
}
chú ý làm c++ nhé !