pascal高端数问题
答案:2 悬赏:10 手机版
解决时间 2021-04-04 16:58
- 提问者网友:练爱
- 2021-04-03 18:01
pascal高端数问题
最佳答案
- 五星知识达人网友:梦中风几里
- 2021-04-03 18:07
var n,a,b,i,i1,i2:integer;
begin
readln(a,b);
for i:=a to b do
begin
i2:=1;
for i1:=2 to trunc(sqrt(i)) do
if i mod i1=0 then begin i2:=0; break end;
if i2=0 then continue;
for i1:=1 to trunc(sqrt(i div 2)) do
begin
i2:=trunc(sqrt(i-i1*i1));
if i-i1*i1-i2*i2=0 then
begin inc(n); writeln(i,'=',i1,'*',i1,'+',i2,'*',i2) end;
end;
end;
writeln('n=',n);
end.
var n,m,c,i,j,x,s:integer;
begin
readln(n,m,c);
for i:=1 to n do
for j:=1 to m do
begin
read(x);
if x=c then inc(s);
end;
writeln(s)
end.追问欧德斯猜想是由匈牙利犹太数学家欧德斯与斯特劳斯于1948年共同提出的数论猜想:对于所有n>1,4/n=1/x+1/y+1/z都有正整数解。那么对于同一个n,有多少组x,y,z符合猜想?这里x,y,z都小于等于100且x 样例输入
5
样例输出
2
提示
符合欧德斯猜想的2组解分别是4/5=1/2+1/4+1/20和4/5=1/2+1/5+1/10。
这题解出了立即采纳,加悬赏!!!追答var n,x,y,z,s:longint;
begin
readln(n);
for x:=1 to 98 do
for y:=x+1 to 99 do
for z:=y+1 to 100 do
if 4*x*y*z=y*z*n+x*z*n+x*y*n then
begin
inc(s);
writeln('4/',n,'=1/',x,'+1/',y,'+1/',z);
end;
writeln(s);
end.
begin
readln(a,b);
for i:=a to b do
begin
i2:=1;
for i1:=2 to trunc(sqrt(i)) do
if i mod i1=0 then begin i2:=0; break end;
if i2=0 then continue;
for i1:=1 to trunc(sqrt(i div 2)) do
begin
i2:=trunc(sqrt(i-i1*i1));
if i-i1*i1-i2*i2=0 then
begin inc(n); writeln(i,'=',i1,'*',i1,'+',i2,'*',i2) end;
end;
end;
writeln('n=',n);
end.
var n,m,c,i,j,x,s:integer;
begin
readln(n,m,c);
for i:=1 to n do
for j:=1 to m do
begin
read(x);
if x=c then inc(s);
end;
writeln(s)
end.追问欧德斯猜想是由匈牙利犹太数学家欧德斯与斯特劳斯于1948年共同提出的数论猜想:对于所有n>1,4/n=1/x+1/y+1/z都有正整数解。那么对于同一个n,有多少组x,y,z符合猜想?这里x,y,z都小于等于100且x
5
样例输出
2
提示
符合欧德斯猜想的2组解分别是4/5=1/2+1/4+1/20和4/5=1/2+1/5+1/10。
这题解出了立即采纳,加悬赏!!!追答var n,x,y,z,s:longint;
begin
readln(n);
for x:=1 to 98 do
for y:=x+1 to 99 do
for z:=y+1 to 100 do
if 4*x*y*z=y*z*n+x*z*n+x*y*n then
begin
inc(s);
writeln('4/',n,'=1/',x,'+1/',y,'+1/',z);
end;
writeln(s);
end.
全部回答
- 1楼网友:白昼之月
- 2021-04-03 19:18
var
a,b:integer;
x,y:integer;
i:integer;
num:integer;
function zhisu(n:longint):boolean;
var
j,k:longint;
findd:boolean;
begin
k:=trunc(sqrt(n));
if n=1 then zhisu:=false
else if (n=2)or(n=3) then zhisu:=true
else begin
findd:=false;
j:=1;
repeat
j:=j+1;
if (n mod j)=0 then findd:=true;
until findd or (j>k);
zhisu:=not findd;
end;
end;
function power_sum(n:longint):boolean;
var
i,m:integer;
bool:boolean;
r:integer;
begin
m:=trunc(sqrt(n));
bool:=false;
for i:=1 to m do begin
r:=n-i*i;
r:=trunc(sqrt(r));
if n=i*i+r*r then begin bool:=true; x:=i;y:=r; break; end;
end;
power_sum:=bool;
end;
begin
{readln(a,b); }
a:=1; b:=100;
num:=0;
for i:=a to b do
if (zhisu(i) and power_sum(i)) then begin
inc(num);
writeln(i:0,'=',x:0,'*',x:0,'+',y:0,'*',y:0);
end;
writeln('num=',num:0);
end.
a,b:integer;
x,y:integer;
i:integer;
num:integer;
function zhisu(n:longint):boolean;
var
j,k:longint;
findd:boolean;
begin
k:=trunc(sqrt(n));
if n=1 then zhisu:=false
else if (n=2)or(n=3) then zhisu:=true
else begin
findd:=false;
j:=1;
repeat
j:=j+1;
if (n mod j)=0 then findd:=true;
until findd or (j>k);
zhisu:=not findd;
end;
end;
function power_sum(n:longint):boolean;
var
i,m:integer;
bool:boolean;
r:integer;
begin
m:=trunc(sqrt(n));
bool:=false;
for i:=1 to m do begin
r:=n-i*i;
r:=trunc(sqrt(r));
if n=i*i+r*r then begin bool:=true; x:=i;y:=r; break; end;
end;
power_sum:=bool;
end;
begin
{readln(a,b); }
a:=1; b:=100;
num:=0;
for i:=a to b do
if (zhisu(i) and power_sum(i)) then begin
inc(num);
writeln(i:0,'=',x:0,'*',x:0,'+',y:0,'*',y:0);
end;
writeln('num=',num:0);
end.
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯