1 / 6
Mar 2011

Can i get a little help with NOVICE21, can´t fix NZEC with this. HElp anyone?

http://www.spoj.pl/files/src/4867940/

using System;
class spoj8214
{
    static void Main()
    {
        //Spoj 8214: determina cuantos numeros entre a y b son divisible entre n
        bool esValido= false;
            long numero;
            esValido = long.TryParse(Console.ReadLine (), out numero);
            while (!esValido)
        {
            esValido = long.TryParse(Console.ReadLine(), out numero);
        }
    long T = numero;
    long A, B, N, t, d, l=0;

    long[] G = new long[T];
    for (t = 1; t <= T; t++)
    {
        LeeABN(out A, out B, out N);
        dividir(out d, A, B, N);
        G[l] = d;
        l++;
    }
    for (long s = 0; s < T; s++)
     {
         Console.WriteLine(G[s]);
     }
}

static void LeeABN(out long A, out long B, out long N)
{
    string a;
    string[] num = new string[3]; // arreglo del string
    a = Console.ReadLine();
    num = a.Split(' ');
    A = Convert.ToInt64(num[0]);
    B = Convert.ToInt64(num[1]);
    N = Convert.ToInt64(num[2]);
}
static void dividir(out long d, long A, long B, long N)
{
    d = 0; 
    for (long c = A; c < B; c++)
    {
        if (c % N == 0)
            d += 1;
    }
}
}

Time Limit Exceed

1
1 1000000000 1

That will take a long time for your code to run. You need to find a quicker method than looping from A to B.

Solve the test case I gave you using only a pencil and paper. Can you do that?

Now do the same test case, but change the divisor to 9. Solve with a pencil and paper again.

If you can do that, then tell the computer to do it the same way you did.