LINUX.ORG.RU

История изменений

Исправление ilammy, (текущая версия) :

#include <stdio.h>

int main()
{
    unsigned int number, prev, substractions, divisions;
    float temp;

    scanf("%d", &number);

    for (substractions = 0; number; substractions++)
    {
        prev = number;
        number &= number - 1;
    }

    temp = (prev & -prev);
    divisions = (*(unsigned*)&temp >> 23) - 0x7F;

    printf("%d\n", substractions + divisions);
}

(Не работает для ноля.)

Исходная версия ilammy, :

#include <stdio.h>

int main()
{
    unsigned int number, prev, substractions, divisions;
    float temp;

    scanf("%d", &number);

    for (substractions = 0; number; substractions++)
    {
        prev = number;
        number &= number - 1;
    }

    temp = (prev & -prev);
    divisions = (*(unsigned*)&temp >> 23) - 0x7F;

    printf("%d\n", substractions + divisions);
}