Спасите девушку!!!!!!!!!

За вознаграждение или нахаляву (если повезёт)

Модераторы: Хыиуду, MOTOCoder, Medved, dr.Jekill

Ответить
July
Сообщения: 1
Зарегистрирован: 06 апр 2007, 11:44

Привет, ребята! Спасите девушку! Требуется помощь!! Помогите, пожалуйста, решить задачу на Pascale функцией и процедурой!!!!!!! ;) Задача:Найти все натуральные числа, не превосходящие заданного числа n, в двоичном представлении которых номера ненулевых разрядов образуют арифметическую прогрессию.
Аватара пользователя
somewhere
Сообщения: 1858
Зарегистрирован: 31 авг 2006, 17:14
Откуда: 71 RUS
Контактная информация:

Код: Выделить всё

Uses crt;

Type
  TByteList = Record  Count : Byte;
                      Items : Array[1..255] of Byte;
              end;

Var
    CurN, MaxN : Integer;
       X, Diff : Byte;
          binr : String;
       poslist : TByteList;
        IsProg : Boolean;
{     Result is string as binary representation of I      }
Function GetBinaryRepresent(I: Integer):String;
var x:Byte;
begin
GetBinaryRepresent := '0000000000000000';
for x:=0 to 15 do GetBinaryRepresent[16-x] := chr($30 + (I shr x) and 1);
end;

{		MAIN PROGRAMM             }
begin
ClrScr;
For CurN := 0 to 10000 do
	begin
	binr := GetBinaryRepresent(CurN);

        PosList.Count := 0;
        for x:=16 downto 1 do
           if binr[x] = '1' then
                begin
                inc(PosList.Count);
                PosList.Items[PosList.Count] := 16-X;
                end;
        IsProg := True;
        if PosList.Count > 2 then
	   begin
           diff := PosList.Items[2] - PosList.Items[1];
           For x := 3 to PosList.Count do
               IsProg := IsProg and (PosList.Items[x] - PosList.Items[x-1] = diff);
           if IsProg then
	       WriteLn(CurN:5, '     ', BinR, '   Formula : ', PosList.Items[1],'+',diff,'x');
           end;
        end;
end.
Так пойдет?
It's a long way to the top if you wanna rock'n'roll
Ответить