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.
uses crt;
var i,n,m,k,d:integer;
{---------------chuong-trinh-con-tim-ucln--------------------}
function ucln(x,y:integer):integer;
var t:integer;
begin
while y<>0 do
begin
t:=x mod y;
x:=y;
y:=t;
end;
ucln:=x;
end;
{------------chuong-trinh-con-kiem-tra-so-nguyen-to-------------------}
function nt(b:longint):boolean;
var j:longint;
begin
nt:=true;
if (b=2) or (b=3) then exit;
nt:=false;
if (b=1) or (b mod 2=0) or (b mod 3=0) then exit;
j:=5;
while j<=trunc(sqrt(b)) do
begin
if (b mod j=0) or (b mod (j+2)=0) then exit;
j:=j+6;
end;
nt:=true;
end;
{---------------chuong-trinh-chinh---------------------}
begin
clrscr;
write('Nhap N: '); readln(N);
write('Nhap M: '); readln(M);
d:=0;
k:=ucln(N,M);
for i:=1 to k do
if nt(i) then d:=d+1;
if d>0 then writeln('2 so nay tuong duong voi nhau')
else writeln('2 so nay khong tuong duong voi nhau');
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long n,i,t,j;
bool kt;
int main()
{
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) cout<<i<<" ";
}
cout<<endl;
t=0;
for (i=1; i<=n; i++)
if (n%i==0) t+=i;
cout<<t;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long n,i;
bool kt;
int main()
{
cin>>n;
kt=true;
for (i=2; i*i<=n; i++)
if (n%i==0) kt=false;
if ((kt==true) and (n>1)) cout<<"YES";
else cout<<"NO";
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long n,i;
int main()
{
cin>>n;
for (i=1; i<=n; i++) if (n%i==0) cout<<i<<" ";
return 0;
}
Bạn sài Quy hoạch động đi
c++:
#include <iostream>
#include <vector>
using namespace std;
const int N = (int) 1e5 + 5;
const int MOD = (int) 1e9;
int a[N];
int n;
int main() {
cin >> n;
if (n == 0) {
cout << 0 << endl;
return 0;
}
vector<int> p;
for (int i = 1;;) {
p.push_back(i * (3 * i - 1) / 2);
if (p.back() >= n) break;
i = -i;
if (i > 0) i++;
}
a[0] = 1;
for (int i = 1; i <= n; ++i) {
int sign = 1, cnt = 0;
for (int j : p) {
if (j > i) break;
a[i] += sign * a[i - j];
if (a[i] < 0) a[i] += MOD;
if (a[i] >= MOD) a[i] -= MOD;
cnt += 1;
if (cnt == 2) {
cnt = 0;
sign = -sign;
}
}
}
cout << a[n] << endl;
return 0;
}
uses crt; var a,b:array[1..100000]of integer; i,n,kt,j,dem,x,y,kt1:integer; st,st1:string; begin clrscr; write('Nhap n='); readln(n); for i:=1 to n do begin write('A[',i,']='); readln(a[i]); end; dem:=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 begin kt:=1; break; end; if kt=0 then begin inc(dem); b[dem]:=a[i]; end; end; for i:=1 to dem do begin str(a[i],st); st1:=''; for j:=length(st) downto 1 do st1:=st1+st[j]; val(st1,x,y); kt1:=0; for j:=2 to x-1 do if x mod j=0 then begin kt1:=1; break; end; if kt1=0 then write(a[i]:4); end; readln; end.
uses crt; var a,b:array[1..100000]of integer; i,n,kt,j,dem,x,y,kt1:integer; st,st1:string; begin clrscr; write('Nhap n='); readln(n); for i:=1 to n do begin write('A[',i,']='); readln(a[i]); end; dem:=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 begin kt:=1; break; end; if kt=0 then begin inc(dem); b[dem]:=a[i]; end; end; for i:=1 to dem do begin str(a[i],st); st1:=''; for j:=length(st) downto 1 do st1:=st1+st[j]; val(st1,x,y); kt1:=0; for j:=2 to x-1 do if x mod j=0 then begin kt1:=1; break; end; if kt1=0 then write(a[i]:4); end; readln; end.
#include <bits/stdc++.h>
using namespace std;
long long s,i,n;
int main()
{
cin>>n;
s=0;
for (i=1; i<=n; i++)
if (i%3==0) s=s+i;
cout<<s;
return 0;
}
uses crt;
var n,i,m,max:integer;
function kt(n:integer):integer;
var j,k:integer
begin
k:=0;
for j:=2 to n do
if (n mod j)=0 then k:=k+1;
kt:=k+1;
end;
begin
readln(n);
if n=1 then write(1)
else
begin
max:=kt(2);
for m:=3 to n do
if max<kt(m) then max:=kt(m);
write(max);
end;
end.
uses crt;
var n,i,s,kt,j,t:longint;
begin
clrscr;
write('Nhap n='); readln(n);
s:=1;
for i:=1 to n do
s:=s*i;
t:=0;
for i:=2 to s do
if s mod i=0 then
begin
kt:=0;
for j:=2 to i-1 do
if i mod j=0 then kt:=1;
if kt=0 then t:=t+i;
end;
writeln('Tong cac uoc nguyen to cua n,'! la: ',t);
readln;
end.
ta dinh nghia nhu sau
n!=n*(n-1)*(n-2)*...*1;
vs 4!=1*2*3*4;
vi the ban chi can tinh tong cac so nguyen to tu 1 den n thoi
ko can tinh n! lam j cho mat tg ,do phuc tap la O(n) nhe