QNUMBER problem

my code takes too long to execute

anyone help…

import java.io.*;
class three
{
    public static void main(String [] args)throws IOException
    {
        BufferedReader x=new BufferedReader(new InputStreamReader(System.in));
        String []parts=(x.readLine()).split(" ");
      
        Double N=Double.parseDouble(parts[0]);
        Double Q=Double.parseDouble(parts[1]);
        for(int i=0;i<Q;i++)
        {
            
            String []a=(x.readLine()).split(" ");
            find(Integer.parseInt(a[0]),Double.parseDouble(a[1]),N);}
    }
    static void find(int t, Double k, Double n)
    {int count=0;
        switch(t)
        {
            case 1:for(int i=1;i<=n||i<=k;i++)
                        {
                if (k%i==0&&n%i==0)
                count++;}
                break;
                case 2: for(int i=0;i<=n;i++)
                {if(n%i==0&&i%k==0)
                count++;}break;
                case 3:for(int i=0;i<=n;i++)
                {if (n%i==0&&i%k!=0)
                count++;}break;
        }
        System.out.println(count);
    }
 
}

read the editorial - QNUMBER - Editorial - editorial - CodeChef Discuss

1 Like