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.
var A:
array[1..n] of int64;
i, n, count: integer;
begin
write('Nhap so phan tu cua mang: ');
readln(n);
for i := 1 to n do
begin
write('Nhap phan tu thu ', i, ': ');
readln(A[i]);
end;
count := 0;
for i := 1 to n do
if A[i] > 0 then
count := count + 1;
writeln('So luong cac so nguyen duong trong mang la: ', count); end.
uses crt;
var n,i,o,d:integer;
function ktnt(n:integer): integer;
var i,d:integer;
begin
d:=0;
for i:=1 to sqrt(n) do
if (n mod i=0) then d:=d+1;
if d=2 then ktnt=0
else ktnt=1;
end;
begin
readln(n);
writeln(' so nguyen to be hon hoac bang n la'); {a}
for i:=1 to n do
if ktnt(i)=0 then writeln(i);
writeln('so nguyen to nho nhat khong be hon n');
o:=n;
while o>0 do
begin
if ktnt(o)=0 then
begin
write(o);
break;
end;
o:=o+1;
end;
writeln('cặp số nguyên tố là hai số nguyên lẻ liên tiếp nhỏ hơn hoặc bằng n');
o:=0;
o:=1;
d:=0;
for i:=o+2 to n do
begin
if ktnt(i)=0 then
begin
d:=d+1;
write(i,' ');
if d<2 then continue;
end;
d:=0;
writeln;
end;
readln;
end.
Ngôn ngữ: C++
#include <bits/stdc++.h>
using namespace std;
long long n;
long long minx=LLONG_MAX;
long long a[100000];
int main()
{
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1);
for(int i=2;i<=n;i++){
minx=min(minx,a[i]-a[i-1]);
}
cout<<minx;
return 0;
}
uses crt;
var n,d,i,t,x,y:integer;
st:string;
begin
clrscr;
write('Nhap n='); readln(n);
if n mod 2=0 then writeln('1')
else writeln('0');
str(n,st);
d:=length(st);
writeln('Cac chu so cua ',n,' la: ');
for i:=1 to d do
write(st[i]:4);
writeln;
t:=0;
for i:=1 to d do
begin
val(st[i],x,y);
t:=t+x;
end;
writeln('Tong cac chu so cua ',n,' la: ',t);
readln;
end.
Bài 1:
uses crt;
var n,d,t,x,y,j,kt,i,t1,dem:integer;
st:string;
a:array[1..255]of integer;
begin
clrscr;
write('n='); readln(n);
if (0<n) and (n<1000) then
begin
{------------------------dong-1---------------------------}
str(n,st);
d:=length(st);
t:=0;
for i:=1 to d do
begin
val(st[i],x,y);
t:=t+x;
end;
writeln('tong cac chu so cua ',n,' la: ',t);
{----------------------dong-2----------------------------}
writeln('cac so nguyen to nho hon tong cac chu so cua ',n,' la: ');
dem:=0;
for i:=2 to t-1 do
begin
kt:=0;
for j:=2 to i-1 do
if i mod j=0 then kt:=1;
if kt=0 then
begin
write(i:4);
dem:=dem+1;
a[dem]:=i;
end;
end;
{----------------dong-3---------------------------}
writeln;
t1:=0;
for i:=1 to dem do
t1:=t1+a[i];
writeln('tong cac so nguyen to trong dong 2 la: ',t1);
end
else writeln('vui long nhap lai');
readln;
end.
Bài 2:
uses crt;
var a,b,i,dem,j,kt:integer;
c:array[1..100]of integer;
begin
clrscr;
write('a='); readln(a);
write('b='); readln(b);
if (20<=a) and (a<=50) and (30<=b) and (b<=75) then
begin
{------------------------dong-1--------------------------}
writeln('cac so co 2 chu so chia het cho 9 la:');
for i:=10 to 99 do
if i mod 9=0 then write(i:4);
{-----------------------dong-2--------------------------}
writeln;
writeln('cac so chinh phuong lon hon ',a,' va nho hon ',b,' la: ');
for i:=a+1 to b-1 do
if trunc(sqrt(i))=sqrt(i) then write(i:4);
{-----------------------dong-3---------------------------}
writeln;
dem:=0;
for i:=2 to b do
begin
kt:=0;
for j:=2 to i-1 do
if i mod j=0 then kt:=1;
if kt=0 then
begin
inc(dem);
c[dem]:=i;
end;
end;
writeln('so nguyen to lon nhat nho hon ',b,' la: ',c[dem]);
end
else writeln('vui long nhap lai');
readln;
end.
Bài 3:
uses crt;
var n,d,t,i,x,y:integer;
st:string;
begin
clrscr;
write('n='); readln(n);
if (0<n) and (n<105) then
begin
{---------------------------dong-1---------------------------}
str(n,st);
d:=length(st);
writeln('so luong cac chu so cua ',n,' la: ',d);
{---------------------------dong-2--------------------------}
t:=0;
for i:=1 to d do
begin
val(st[i],x,y);
t:=t+x;
end;
writeln('tong cac chu so cua ',n,' la: ',t);
{---------------------------dong-3------------------------}
writeln('phan so toi gian cua ',n,' la: 1/',n);
write('so dao nguoc cua ',n,' la: ');
for i:=d downto 1 do
write(st[i]);
end
else writeln('vui long nhap lai');
readln;
end.
Câu 1:
Program hotrotinhoc;
var i,tog,n: integer;
function tong(x: integer): integer;
var k,t: longint;
begin
t:=0;
while x<>0 do
begin
k:=x mod 10;
t:=t+k;
x:=x div 10;
end;
tong:=t;
end;
function nt(a: integer): boolean;
var j: integer;
begin
nt:=true;
if (a=2) or (a=3) then exit;
nt:=false;
if (a=1) or (a mod 2=0) or (a mod 3=0) then exit;
j:=5;
while (j<=trunc(sqrt(a))) do
begin
if (a mod j=0) or (a mod (j+2)=0) then exit;
j:=j+6;
end;
nt:=true;
end;
begin
write('Nhap so nguyen N :'); readln(n);
writeln('Tong cac chu so cua N la :',tong(n));
write('Cac so nguyen to nho hon tong cac chu so cua N la :');
for i:=1 to tong(n) do if nt(i) then
begin
write(i,' ');
tog:=tog+i;
end;
writeln;
write('Tong cac so nguyen to trong dong 2 la :',tog);
readln
end.
#include <iostream>
#include <vector>
using namespace std;
pair<int, int> findMaxSubarray(vector<int> nums) {
int n = nums.size();
int maxSum = nums[0];
int currentSum = nums[0];
int start = 0;
int end = 0;
for (int i = 1; i < n; i++) {
if (currentSum < 0) {
currentSum = nums[i];
start = i;
end = i;
} else {
currentSum += nums[i];
end = i;
}
if (currentSum > maxSum) {
maxSum = currentSum;
}
}
return make_pair(start, end);
}
int main() {
int numTests;
cin >> numTests;
for (int t = 0; t < numTests; t++) {
int n;
cin >> n;
vector<int> nums(n);
for (int i = 0; i < n; i++) {
cin >> nums[i];
}
pair<int, int> maxSubarray = findMaxSubarray(nums);
cout << maxSubarray.first << " " << maxSubarray.second << endl;
}
return 0;
}
Tham Khảo:
#include <bits/stdc++.h>
using namespace std;
bool v(int y, int x) {
return 1 <= y && y <= 8 && 1 <= x && x <= 8;
}
int m(int y, int x, int ty, int tx) {
if (!v(y, x) || !v(ty, tx)) {
return -1;
}
deque<pair<int, pair<int, int>>> q;
q.push_back({y, {x, 0}});
bool vis[9][9] = {false};
vis[y][x] = true;
int dx[] = {-2, -2, 2, 2};
int dy[] = {-2, 2, -2, 2};
while (!q.empty()) {
int cy = q.front().first;
int cx = q.front().second.first;
int s = q.front().second.second;
q.pop_front();
if (cy == ty && cx == tx) {
return s;
}
for (int i = 0; i < 4; ++i) {
int ny = cy + dy[i];
int nx = cx + dx[i];
if (v(ny, nx) && !vis[ny][nx]) {
q.push_back({ny, {nx, s + 1}});
vis[ny][nx] = true;
}
}
}
return -1;
}
int main() {
int y, x, ty, tx;
cin >> y >> x >> ty >> tx;
cout << m(y, x, ty, tx) << endl;
return 0;
}
uses crt;
var i,n:integer;
begin
clrscr;
readln(n);
for i:=1 to n do
if i mod 2=1 then write(i:4);
readln;
end.