POJ2603 fundemental theorm arithmetic&& the num of divisor

As we all known, any integer greater than 1 can wrriten as unqie product of primes numbers.


for example :100=(2^2)*(5^2);


As for p=(p1^e1)*(p2^e2)*(p3^e3).....(pn^en),the num of of divisors of p is ans=(e1+1)*(e2+1)*(e3+1)..........(en+1);



#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN=10000;
int divisor[MAXN+10];
bool prime[MAXN+10]={1,1,0};
int main()
{
  
  int i;
  int n;
  int j;
  for(i=2;i<=MAXN;i++)
    {
      if(prime[i]==0)
	{
	  for(j=i+i;j<=MAXN;j+=i)
	    {
	      prime[j]=1;
	  
	    }
      
	}
    }
  memset(divisor,0,sizeof(divisor));
  int ans=1;
  for(j=0;j<10;j++)
    {
      scanf("%d",&n);
      if(n==0)
	{
	  
	  ans=0;
	  continue;
	}
      for(i=2;i<=n;i++)
	{
	  if(prime[i]==0&&n%i==0)
	    {
	      while(n%i==0)
		{
		  	      n/=i;
			      divisor[i]++;

		}
	      
	      



	      
	    }
	}
    }

  for(i=2;i<=MAXN;i++)
    {
      if(divisor[i]!=0)
	{
	  ans*=(divisor[i]+1);
	}
      
    }
  printf("%d\n",ans%10);
  return 0;
}



 

你可能感兴趣的:(POJ2603 fundemental theorm arithmetic&& the num of divisor)