Em hãy viết chương trình tính lũy thừa bậc n của số nguyên X(Ai giải hộ trước ngày 29-2-2020 với)
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.
![](https://rs.olm.vn/images/avt/0.png?1311)
![](https://rs.olm.vn/images/avt/0.png?1311)
Làm bằng pascal thì những bài như thế này thì test lớn chạy không nổi đâu bạn
#include <bits/stdc++.h>
using namespace std;
long long n,a,b;
int main()
{
cin>>n;
a=1;
while (pow(a,3)<=n)
{
a++;
}
if (pow(a,3)==n) cout<<"YES";
else cout<<"NO";
cout<<endl;
b=1;
while (pow(5,b)<=n) do b++;
if (pow(5,b)==n) cout<<"YES";
else cout<<"NO";
cout<<endl<<pow(n,n)%7;
return 0;
}
![](https://rs.olm.vn/images/avt/0.png?1311)
c++:
#include <iostream>
using namespace std;
int main(){
int y;
cin >> y;
int i = 1;
int luythua = 1;
while(i<=y){
luythua = luythua *i;
i = i+1;
}
cout << luythua;
}
![](https://rs.olm.vn/images/avt/0.png?1311)
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln(t);
readln;
end.
![](https://rs.olm.vn/images/avt/0.png?1311)
Bài 1:
function canbac2(x:longint):real;
begin
canbac2:=sqrt(x);
end;
Bài 2:
function tong(n:longint):longint;
var s,i:longint;
begin
s:=0;
for i:=1 to n do
s:=s+i;
tong:=s;
end;
![](https://rs.olm.vn/images/avt/0.png?1311)
Bài 1:
uses crt;
var s,i:integer;
begin
clrscr;
s:=0;
for i:=3 to 372 do
if i mod 3=0 then s:=s+i;
writeln(s);
readln;
end.
Bài 2:
uses crt;
var n,i,t,x,y,d:integer;
st:string;
begin
clrscr;
write('Nhap n='); readln(n);
str(n,st);
t:=0;
d:=length(st);
for i:=1 to d do
begin
val(st[i],x,y);
t:=t+x;
end;
writeln(t);
readln;
end.
![](https://rs.olm.vn/images/avt/0.png?1311)
Gọi x1,x2 là các nghiệm của phương trình đã cho
Áp dụng hệ thức Vi-et,ta có :
x1 + x2 = -5 ; x1x2 = -1
gọi y1,y2 là các nghiệm của phương trình phải lập,ta được :
y1 + y2 = x14 + x24 , y1y2 = x14x24
Ta có : x12 + x22 = ( x1 + x2 )2 - 2x1x2 = 25 + 2 - 27
Do đó : y1 + y2 = x14 + x24 = ( x12 + x22 )2 - 2x12x22 = 729 - 2 = 727
y1y2 = ( x1x2 )4 = 1
Từ đó pt phải lập có dạng : y2 - 727y + 1 = 0
Ta co: P = -1 <0
=> (1) có 2 nghiệm phân biệt khác dấu
Gọi hai nghiệm đó là \(x_1;x_2\)
=> \(x_1+x_2=-5;x_1.x_2=-1\)
Ta có: \(\left(x_1.x_2\right)^4=\left(-1\right)^4=1\)
\(\left(x_1\right)^4+\left(x_2\right)^4=\left(x_1^2+x_2^2\right)^2-2x_1^2x_2^2=\left[\left(x_1+x_2\right)^2-2x_1x_2\right]^2-2x_1^2x_2^2\)
\(=\left[\left(-5\right)^2-2.\left(-1\right)\right]^2-2.\left(-1\right)^2\)
\(=727\)
=> Phương trình có các nghiệm lũy thừa bậc 4 của các nghiệm phương trình (1) là:
\(x^2-727x+1=0\)
uses crt;
var x,n,i:integer;
lt:longint;
begin
clrscr;
write('co so x='); readln(x);
write('so mu n='); readln(n);
lt:=1;
for i:=1 to n do
lt:=lt*x;
writeln(x,'^',n,'=',lt);
readln;
end.