begin for i := 1000 to 9999 do begin x := i; s := 0; while x > 0 do begin s := s + (x mod 10) * (x mod 10); x := x div 10; end; if (s mod 2 = 0) or (s mod 3 = 0) then begin k := k + 1; {writeln(i:5,s:5);} end; end;
Dim i As Integer Dim s As Integer Dim d As Integer
For i = 1000 To 9999 s = CInt((CInt(Mid(CStr(i), 1, 1))) ^ 2 + (CInt(Mid(CStr(i), 2, 1))) ^ 2 + (CInt(Mid(CStr(i), 3, 1))) ^ 2 + (CInt(Mid(CStr(i), 4, 1))) ^ 2) If s Mod 2 = 0 Or s Mod 3 = 0 Then d += 1 Next MsgBox(d)
прощения за ответ, перепутал и соединил две задачи=)
x, s, k, i: integer;
begin
for i := 1000 to 9999 do
begin
x := i;
s := 0;
while x > 0 do
begin
s := s + (x mod 10) * (x mod 10);
x := x div 10;
end;
if (s mod 2 = 0) or (s mod 3 = 0) then begin
k := k + 1;
{writeln(i:5,s:5);}
end;
end;
writeln(k);
end.
ответ 6216
Dim i As Integer
Dim s As Integer
Dim d As Integer
For i = 1000 To 9999
s = CInt((CInt(Mid(CStr(i), 1, 1))) ^ 2 + (CInt(Mid(CStr(i), 2, 1))) ^ 2 + (CInt(Mid(CStr(i), 3, 1))) ^ 2 + (CInt(Mid(CStr(i), 4, 1))) ^ 2)
If s Mod 2 = 0 Or s Mod 3 = 0 Then d += 1
Next
MsgBox(d)
прощения за ответ, перепутал и соединил две задачи=)