10110 - Light, more light

All about problems in Volume 101. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

This Is ERFAN
New poster
Posts: 6
Joined: Thu Dec 04, 2014 11:40 pm

Re: 10110 - Light, more light

Post 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;
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Slow algorithm

Post by brianfry713 »

brianfry713 wrote:You can solve for each input value in constant time using sqrt().
Your algorithm O(n) is too slow.
Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 101 (10100-10199)”