Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODULE kolok;
- FROM InOut IMPORT WriteString,WriteLn,ReadInt,WriteInt;
- CONST maxn=30;
- maxr=20;
- sk={0,1,4,9};
- TYPE niz= ARRAY [0..maxr] OF INTEGER;
- (*A*)
- PROCEDURE grec(n,r:INTEGER):INTEGER; FORWARD;
- PROCEDURE frec(n,r:INTEGER):INTEGER;
- BEGIN
- IF n<r THEN
- RETURN n
- ELSE
- IF n MOD 10 IN sk THEN
- RETURN frec(n-r,r)-frec(n-r+1,r)+grec(n-r+2,r)-grec(n-r+1,r)
- ELSE
- RETURN -frec(n-1,r)+grec(n-r,r)-frec(n-r+2,r)-grec(n-1,r)
- END;
- END;
- END frec;
- PROCEDURE grec(n,r:INTEGER):INTEGER;
- BEGIN
- IF n<r THEN
- RETURN -n
- ELSE
- IF n DIV 2 = 0 THEN
- RETURN 3*frec(n-2,r)+2*(grec(n-r+2,r)-frec(n-r+3,r))-grec(n-r,r);
- ELSE
- RETURN -grec(n-r+1,r)-frec(n-2,r)
- END;
- END;
- END grec;
- (*B*)
- PROCEDURE frec2(n,r:INTEGER):INTEGER;
- PROCEDURE FG(f,g:niz; i:INTEGER):INTEGER;
- VAR j:INTEGER;
- BEGIN
- IF i>n THEN
- RETURN f[r]
- ELSE
- IF i MOD 10 IN sk THEN
- f[r]:=f[0]-f[1]+g[2]-g[1];
- ELSE
- f[r]:=-f[r-1]+g[0]-f[2]-g[r-1];
- END;
- IF i DIV 2 = 0 THEN
- g[r]:=3*f[r-2]+2*(g[2]-f[3])-g[0];
- ELSE
- g[r]:=-g[1]-f[r-2];
- END;
- FOR j:=0 TO r-1 DO
- f[j]:=f[j+1];
- g[j]:=g[j+1];
- END;
- RETURN FG(f,g,i+1);
- END;
- END FG;
- VAR f,g:niz;
- j:INTEGER;
- BEGIN
- IF n<r THEN
- RETURN n
- ELSE
- FOR j:=0 TO r-1 DO
- f[j]:=j;
- g[j]:=-j;
- END;
- RETURN FG(f,g,r);
- END;
- END frec2;
- (*C*)
- PROCEDURE fiter(n,r:INTEGER):INTEGER;
- VAR f,g:niz;
- i,j:INTEGER;
- BEGIN
- FOR i:=0 TO r-1 DO
- f[i]:=i;
- g[i]:=-i;
- END;
- IF n<r THEN
- RETURN f[n]
- ELSE
- FOR i:=r TO n DO
- IF i MOD 10 IN sk THEN
- f[r]:=f[0]-f[1]+g[2]-g[1];
- ELSE
- f[r]:=-f[r-1]+g[0]-f[2]-g[r-1];
- END;
- IF i DIV 2 = 0 THEN
- g[r]:=3*f[r-2]+2*(g[2]-f[3])-g[0];
- ELSE
- g[r]:=-g[1]-f[r-2];
- END;
- FOR j:=0 TO r-1 DO
- f[j]:=f[j+1];
- g[j]:=g[j+1];
- END;
- END;
- END;
- RETURN f[r];
- END fiter;
- (*glavni program*)
- VAR n,r:INTEGER;
- BEGIN
- REPEAT
- WriteString('Unesite n (0<=n<=');
- WriteInt(maxn,1);
- WriteString('): ');
- ReadInt(n);
- UNTIL (0<=n) AND (n<=maxn);
- REPEAT
- WriteString('Unesite r (6<=r<=');
- WriteInt(maxr,1);
- WriteString('): ');
- ReadInt(r);
- UNTIL (6<=r) AND (r<=maxr);
- WriteString('Frec1(n,r)=');
- WriteInt(frec(n,r),5);
- WriteLn;
- WriteString('Frec2(n,r)=');
- WriteInt(frec2(n,r),5);
- WriteLn;
- WriteString('Fiter(n,r)=');
- WriteInt(fiter(n,r),5);
- WriteLn;
- END kolok.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement