Page 6 of 6

Re: 10110 - Light, more light

Posted: Sun Dec 14, 2014 2:17 am
by This Is ERFAN
Why getting time limit...?? Check it out plz..

Code: Select all

#include<stdio.h>

int main()
{
    long long int a,i;
    while(scanf("%lld",&a))
    {
        if(a==0) return 0;
        long long int temp=a;
        for(i=1;i<=a;i++)
        {
            if(a%i==0) temp=temp*(-1);
            else continue;
        }
        if(temp<0) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}

Re: Slow algorithm

Posted: Tue Dec 16, 2014 12:51 am
by brianfry713
brianfry713 wrote:You can solve for each input value in constant time using sqrt().
Your algorithm O(n) is too slow.