1 / 13

var n,i,ans:integer; function gcd (a,b :integer) : integer; begin if a mod b=0 then gcd := b

十八届第二题. var n,i,ans:integer; function gcd (a,b :integer) : integer; begin if a mod b=0 then gcd := b else gcd := gcd (b,a mod b); end; begin readln(n); ans := 0; for i:=1 to n do if gcd(n,i)=i then ans := ans + 1; writeln(ans); end. 输入:120 输出:_____________.

mieko
Download Presentation

var n,i,ans:integer; function gcd (a,b :integer) : integer; begin if a mod b=0 then gcd := b

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 十八届第二题 var n,i,ans:integer; function gcd(a,b :integer) : integer; begin if a mod b=0 then gcd :=b else gcd := gcd(b,a mod b); end; begin readln(n); ans := 0; for i:=1 to n do if gcd(n,i)=ithen ans := ans + 1; writeln(ans); end. 输入:120 输出:_____________

  2. var n,i,ans:integer; function gcd(a,b :integer) : integer; begin if a mod b=0 then gcd :=b else gcd := gcd(b,a mod b); end; begin readln(n); ans := 0; for i:=1 to n do if gcd(n,i)=ithen ans := ans + 1; writeln(ans); end. 输入:120 输出:_____________ 120=1*2*6*10 120=1*2*2*3*2*5 8 1 2 3 4 5 6 12 24 10 15 20 30 40 60 120

  3. 十四届第二题 2.procedure foo(a,b,c:integer); begin if a>b then foo(c,a,b) else writeln(a,',',b,',',c) end; var a,b,c:integer; begin readln(a,b,c); foo(a,b,c); end. 输入:2 1 3 输出:_________________

  4. 十四届第二题 2.procedure foo(a,b,c:integer); begin if a>b then foo(c,a,b) else writeln(a,',',b,',',c) end; var a,b,c:integer; begin readln(a,b,c); foo(a,b,c); end. 输入:2 1 3 输出:_________________ 2 1 3 3 2 1 1 3 2

  5. 十四届第三题 procedure f(a,b,c:integer); begin write(a,b,c,'/'); If (a=3)and(b=2)and(c=1) then exit; if (b<c) then f(a,c,b) else if a<b then if a<c then f(c,a,b) else f(b,c,a); end; var a,b,c:integer; begin readln(a,b,c); f(a,b,c); end. 输入:1 3 2

  6. 十四届第三题 y procedure f(a,b,c:integer); begin write(a,b,c,'/'); If (a=3)and(b=2)and(c=1) then exit; if (b<c) then f(a,c,b) else if a<b then if a<c then f(c,a,b) else f(b,c,a); end; var a,b,c:integer; begin readln(a,b,c); f(a,b,c); end. 输入:1 3 2 b<c n f(a,c,b) y a<b y a<c n f(c,a,b) f(b,c,a)

  7. 132/213/231/312/321/

  8. 十五届第一题 var a,b:integer; function work(a,b:integer):integer; begin if a mod b <> 0 then work := work(b,a mod b) else work := b; end; begin read(a,b); writeln(work(a,b)); end. 输入:123 321

  9. 十五届第一题 var a,b:integer; function work(a,b:integer):integer; begin if a mod b <> 0 then work := work(b,a mod b) else work := b; end; begin read(a,b); writeln(work(a,b)); end. 输入:123 321 3

  10. ACSII码(美国标准信息交换码) AmericanStandardCode forInformationInterchange

  11. program ex1188; var st1,st2:string; a,b:array[1..250] of integer; len1,len2,len,c,i:integer; begin readln(st1); len1:=length(st1); readln(st2); len2:=length(st2); for i:=1 to len1 do a[i]:=ord(st1[len1-i+1])-48; for i:=1 to len2 do b[i]:=ord(st2[len2-i+1])-48; if len1>len2 then len:=len1 else len:=len2; c:=0; for i:=1 to len do begin a[i]:=a[i]+b[i]+c; c:=a[i] div 10; a[i]:=a[i] mod 10; end; if c<>0 then write(c); for i:=len downto 1 do write(a[i]); end.

  12. var s:string; i,j,len,k:integer; begin readln(s); len:=length(s); for i:=1 to len do if (ord(s[i])>=ord('A')) and (ord(s[i])<=ord('Z')) then s[i]::=chr(ord(s[i])-ord('A')+ord('a')); for i:=1 to len do if (ord(s[i])<ord('x')) then s:=chr(ord(s[i])+3) else s[i]:=chr(ord(s[i])-23); write(s); write('/'); for j:=1 to 3 do begin i:=1; while i<=len-j do begin s[i]:=s[i+j]; i:=i+j; end; end; writeln(s); end. 十五届第四题 输入:ABCDEFGuvwxyz 输出:________________________________

  13. abcdefghijklmnopqrstuvwxyz var s:string; i,j,len,k:integer; begin readln(s); len:=length(s); for i:=1 to len do if (ord(s[i])>=ord('A')) and (ord(s[i])<=ord('Z')) then s[i]:=chr(ord(s[i])-ord('A')+ord('a')); for i:=1 to len do if (ord(s[i])<ord('x')) then s[i]:=chr(ord(s[i])+3) else s[i]:=chr(ord(s[i])-23); for i:=1 to len do write(s[i]); write('/'); for j:=1 to 3 do begin i:=1; while i<=len-j do begin s[i]:=s[i+j]; i:=i+j; end; end; for i:=1 to lenwriteln(s[i]); end. 输入:ABCDEFGuvwxyz 13 abcdefguvwxyz defghijxyzabc defghijxyzabc

More Related