49 lines
1 KiB
Text
49 lines
1 KiB
Text
define N = 100;
|
|
define NN = (N * (N+1)) >> 1;
|
|
|
|
func Contains(Lst, Item, Size);
|
|
int Lst, Item, Size, I;
|
|
[for I:= Size-1 downto 0 do
|
|
if Item = Lst(I) then return true;
|
|
return false;
|
|
];
|
|
|
|
int MC(N);
|
|
|
|
proc MianChowla;
|
|
int Sums(NN), Sum, LE, SS, I, J, K;
|
|
[MC(0):= 1;
|
|
Sums(0):= 2;
|
|
SS:= 1;
|
|
for I:= 1 to N-1 do
|
|
[LE:= SS;
|
|
J:= MC(I-1) + 1;
|
|
MC(I):= J;
|
|
K:= 0;
|
|
loop [Sum:= MC(K) + J;
|
|
if Contains(Sums, Sum, SS) then
|
|
[SS:= LE;
|
|
J:= J+1;
|
|
MC(I):= J;
|
|
K:= 0;
|
|
]
|
|
else
|
|
[Sums(SS):= Sum;
|
|
SS:= SS+1;
|
|
K:= K+1;
|
|
if K > I then quit;
|
|
];
|
|
];
|
|
];
|
|
];
|
|
|
|
int I;
|
|
[MianChowla;
|
|
Text(0, "The first 30 terms of the Mian-Chowla sequence are:^m^j");
|
|
for I:= 0 to 30-1 do
|
|
[IntOut(0, MC(I)); ChOut(0, ^ )];
|
|
Text(0, "^m^j^m^jTerms 91 to 100 of the Mian-Chowla sequence are:^m^j");
|
|
for I:= 90 to 100-1 do
|
|
[IntOut(0, MC(I)); ChOut(0, ^ )];
|
|
CrLf(0);
|
|
]
|