Code mình hơi dài, bạn coi có lỗi nào ko nha:
var n,k,dem:byte; heso,a,i:longint;
function testnt(b:longint):boolean;
var j:longint;
begin
if b>1 then
begin
testnt:=true;
for j:=2 to b-1 do
if b mod j = 0 then begin testnt:=false; break; end;
end
else testnt:=false;
end;
function testdd(b:longint):boolean;
var j,temp,temp2:longint; frag:integer; st:string;
begin
if b>1 then
str(b, st);
frag:=0; testdd:=true;
for j:=1 to length(st)-1 do
begin
val(st[j], temp); val(st[j+1], temp2);
if temp-temp2<>0 then
if ((temp-temp2) div abs(temp-temp2)<>frag) then
frag:=(temp-temp2) div abs(temp-temp2)
else begin testdd:=false; break; end
else begin testdd:=false; break; end;
end;
end;
begin
dem:=0;
read(n);
for i:=1 to n do
begin
read(a);
if testnt(a) and testdd(a) then inc(dem);
end;
writeln(dem);
read(k); heso:=1; a:=978563412;
for i:=1 to k do heso:=heso*10;
for i:=1 to 9-k do a:=a div 10;
for i:=a downto a-20 do
if testnt(i) and testdd(i) then begin writeln(i); break; end;
end.
Note: Ừ thì hơi dài dòng tí :))
$\\$
using System;
class prime{
int[] p;
public prime(){
p = new int[1000000];
for (int i=2; i*i<=1000000; i++){
for (int j=i*i; j<1000000; j+=i){
p[j] = -1;
}
}
}
public bool is_prime(int vt){
return p[vt]==0;
}
}
class ntdd{
int m,k,n,v;
int[] list,listf1,listf2,listf3;
prime ip;
public ntdd(int[] lst, int n){
this.n = n;
ip = new prime();
list = new int[n];
for (int i=0; i<n; i++){
list[i] = lst[i];
}
}
private void filter_prime(){
listf1 = new int[n];
for (int i=0; i<n; i++){
if (ip.is_prime(list[i]) && list[i]>=10){
listf1[m] = list[i];
m++;
}
}
}
private bool is_monotonic(string ht){
int g = -1;
for (int i=1; i<ht.Length; i++){
if (g == -1){
if (ht[i-1] < ht[i]){
g = 0;
}
else if (ht[i-1] > ht[i]){
g = 1;
}
else{
return false;
}
}
else if (g == 0){
if (ht[i-1] > ht[i]){
g = 1;
}
else{
return false;
}
}
else if (g == 1){
if (ht[i-1] < ht[i]){
g = 0;
}
else{
return false;
}
}
}
return true;
}
private void filter_monotonic(){
listf2 = new int[m];
for (int i=0; i<m; i++){
if (is_monotonic(listf1[i].ToString())){
listf2[k] = listf1[i];
k++;
}
}
}
public void filter(){
filter_prime();
filter_monotonic();
}
public int get(){
return k;
}
private void _sort(){
for (int i=0; i<v; i++){
for (int j=i+1; j<v; j++){
if (listf3[i]>listf3[j]){
int tam = listf3[i];
listf3[i] = listf3[j];
listf3[j] = tam;
}
}
}
}
private void sorted(int _k){
listf3 = new int[k];
for (int i=0; i<k; i++){
if (listf2[i].ToString().Length == _k){
listf3[v] = listf2[i];
v++;
}
}
_sort();
}
public int max(int _k){
sorted(_k);
return listf3[v-1];
}
}
public class main{
public static void Main(string[] args){
Console.Write("n = ");
int n = int.Parse(Console.ReadLine());
int[] a = new int[n];
for (int i=0; i<n; i++){
Console.Write("a[{0}] = ",i);
a[i] = int.Parse(Console.ReadLine());
}
ntdd l = new ntdd(a,n);
l.filter();
Console.WriteLine("so luong so nguyen to don dieu: {0}",l.get());
Console.Write("k = ");
int k = int.Parse(Console.ReadLine());
Console.WriteLine("so don dieu lon nhat co {0} chu so: {1}",k,l.max(k));
}
}
$\\$
`@Daoanhviet96`
Tin học, tiếng Anh: informatics, tiếng Pháp: informatique, là một ngành khoa học chuyên nghiên cứu quá trình tự động hóa việc tổ chức, lưu trữ, xử lý và truyền dẫn thông tin của một hệ thống máy tính cụ thể hoặc trừu tượng (ảo). Với cách hiểu hiện nay, tin học bao hàm tất cả các nghiên cứu và kỹ thuật có liên quan đến việc mô phỏng, biến đổi và tái tạo thông tin.
Nguồn : Wikipedia - Bách khoa toàn thưLớp 8 - Năm thứ ba ở cấp trung học cơ sở, học tập bắt đầu nặng dần, sang năm lại là năm cuối cấp áp lực lớn dần nhưng các em vẫn phải chú ý sức khỏe nhé!
Nguồn : ADMIN :))Xem thêm tại https://loigiaisgk.com/cau-hoi or https://giaibtsgk.com/cau-hoi
Copyright © 2021 HOCTAPSGK