You are not logged in. Please login at www.codechef.com to post your questions!

×

getting wrong answer in NUMFACT

#include<stdio.h>
//#include<conio.h>
#include<math.h> 
  int pi=-1,prime[50],count[50];
  int primenum(long long a)
  {  int i,f=1;
      for(i=2;i<=a/2;i++)
      {  
        if(a%i==0)
        {f=0;
        break;
        } 
      }
        return f;
  }
    void push(long long a)
    {  int i,f=0;
       for(i=0;i<=pi;i++)
       { if(prime[i]==a)
          {count[i]++;
          f=1;
          break;                      
          } 
       }
        if(f==0)
        {prime[++pi]=a;
        count[pi]=1;
        }   
   }

   int main()
   {   
       long long a,po,k;
       int n,t,i,j,f,fl,l,m;
       scanf("%d",&t);
       for(i=1;i<=t;i++)
  {      po=1;
       for(m=0;m<50;m++)
       {prime[m]=0;
       count[m]=0;
       } pi=-1;
         scanf("%d",&n);
         for(j=1;j<=n;j++)
         {  k=2;
           scanf("%lld",&a);
           f=primenum(a);
           if(f==1)
            push(a);
           else
           {   for(k=2;k<=sqrt(a)+1;k++)

             { 
                 while(a%k==0)
                 {  fl=primenum(k);
                   if(fl==1)
                   {push(k);
                   a=a/k;
                   } 
                 else k++;
                }


            }   
         }
     }
         for(l=0;l<=pi;l++)
          po=po*(count[l]+1);
        printf("%lld",po);

         }
  //       getch();
         return 0;
         }

asked 16 Oct '14, 00:20

sarique's gravatar image

1★sarique
-1119
accept rate: 0%

edited 19 Oct '14, 07:22

topcoder_7's gravatar image

2★topcoder_7
2.9k3153


Brother, let me try to help you...

Try this test case

1
2
1009 9973

Remember : you have to factorize those Ais, each of them is up to 1.000.000 (10^6), there are 168 primes only less than 1000, so you are not dealing with such a big numbers...

link

answered 16 Oct '14, 23:11

topcoder_7's gravatar image

2★topcoder_7
2.9k3153
accept rate: 9%

Please indent the code properly.anyways if u think ur logic is right,then try putting '\n' after %lld in third last line,i.e it should be written as printf("%lld\n",po); instead of printf("%lld",po).Try this first and let me know.

link

answered 16 Oct '14, 06:31

sandeep9's gravatar image

3★sandeep9
4782827
accept rate: 4%

edited 16 Oct '14, 06:32

not working it is not still working after using printf("%lld\n",po); instead of printf("%lld",po)

(16 Oct '14, 21:59) sarique1★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×856

question asked: 16 Oct '14, 00:20

question was seen: 488 times

last updated: 19 Oct '14, 07:22