Presentation is loading. Please wait.

Presentation is loading. Please wait.

安庆市第四中学 解题报告 7(9)班 陈曦.

Similar presentations


Presentation on theme: "安庆市第四中学 解题报告 7(9)班 陈曦."— Presentation transcript:

1 安庆市第四中学 解题报告 7(9)班 陈曦

2 质数问题 积木块数

3 质数问题 质数指除了1和它本身以外不再有其他的除数整除。 所以,只要被除1和本身以外整除,就标志为假。
最后,进行判断,真即为质数,假即为合数。 (1要排除,1既不是质数,也不是合数)

4 var n,i,j,f:longint; begin read(n); for i:=2 to n do f:=0; for j:=1 to trunc(sqrt(i)) do if i mod j=0 then inc(f); if f=1 then write(i,' '); end; end.

5 筛法 var a:array[1..100]of boolean; i,j,n:longint; begin read(n); for i:=2 to n do for j:=2 to n do a[i*j]:=true; for i:=2 to n do if a[i]=false then write(i,' '); end.

6 递归 var n,i:longint; function judge(s:longint):boolean; j:longint; f:boolean; begin f:=true; for j:=2 to trunc(sqrt(s)) do if s mod j=0 then begin f:=false;break;end; judge:=f; end; read(n); for i:=2 to n do if judge(i)=true then write(i,' '); end.

7 积木块数 积木的第一层是1 积木的第二层是1+(1+2) 积木的第三层是1+(1+2)+(1+2+3) 积木的第四层是1+(1+2)+(1+2+3)+( )

8 var n,x,i,s:longint; begin read(n);s:=0;x:=0; for i:=1 to n do s:=s+i; x:=x+s; end; write(x); end.

9 递归 var n:longint; function ans(n:longint):longint; x,i,s:longint; begin s:=0;x:=0; for i:=1 to n do s:=s+i; x:=x+s; end; ans:=x; read(n); write(ans(n)); end.


Download ppt "安庆市第四中学 解题报告 7(9)班 陈曦."

Similar presentations


Ads by Google