Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Why WA ?????

Posted by Kylix at 2009-09-05 00:11:13 on Problem 3604
#include <stdio.h>
#include <iostream>
using namespace std;

#define MAX 3000
#define MAXPRIME 2240

int veces[MAXPRIME + 1],f = 0,aux;
int factor[MAXPRIME + 1];
bool criba[MAX] = {0} ;
int primos[MAXPRIME + 1];

void init_criba(){

        int cant = 0;
        primos[cant++] = 2;

        for (int i=3;i<=MAX ;i+=2)
        {
            if(!criba[i]){
               primos[cant++] = i;
                for(int j=2;j<=MAX/i;j++)
                  criba[i*j] = true;
            }
        }
}//criba


void inserta_factor(int fact){
  if (fact != aux)
    f++,
    factor[f-1] = fact,
    veces[f-1]  = 1,
    aux = fact;
  else
    veces[f-1]++;
}

void factoriza(int n){
  int i = 0;

  while(primos[i]*primos[i] <= n)
    if (n % primos[i] == 0)
      inserta_factor(primos[i]),
      n /= primos[i];
        else i++; 
  if (n > 1) inserta_factor(n);
}  

int divNumbers( int n ){

  int div = 1;
  factoriza( n );
  for (int i=0; i<f; i++)
    div *= veces[i]+1;
  return div;

}



int main()
{
     init_criba();
     int p,number;
     __int64 result = 0;
     scanf("%d",&p);
       while( p-- )
        {
          scanf("%d",&number);
           int counter = divNumbers( number );
              for(int i=1;i<=counter;i++)
                result+= i*i*i;            
              printf("%I64d\n",result);
              result = 0;
              f = 0;
              aux = 0;
        }
       return 0;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator