Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Packaging Cupcakes-Time limit exceeded error

$
0
0

I changed cin/cout to scanf/printf but still it gives me time limit exceeded error.Can someone please tell me how to rectify it?

#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{

int t,a,max,rem,i;

   scanf("%d",&t);

   rem=0;

   while(t>0)

    {

        scanf("%d",&a);

        for(i=2;i<=a;i++)

          {

              if(a%i>=rem)

                {

                    rem=a%i;

                    max=i;

                }

          }

        printf("%d\n",max);

        t--;

    }

   return 0;

}

Viewing all articles
Browse latest Browse all 40121


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>