poj 2603 Brave balloonists

这个题就是欧拉定理的简单运用:

View Code
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<algorithm>

#include<cmath>

#include<queue>

#include<set>

#include<map>

#include<cstring>

#include<vector>

#include<string>

#define LL long long

using namespace std;

int prime[1300],cnt=0,num[10];

void Prime( )

{

    bool hash[5024]= {0};

    for( int i =3 ; i <= 100; i +=2 )

    {

         if( !hash[i>>1] )

         {

           int x = i << 1;

           for( int j = i * i ; j <= 10000; j += x )

                hash[j>>1] = true;

         }

    }    

    prime[cnt++] =2;

    for( int i = 1 ; i <= 5000 ; i ++ )

    {

        if( !hash[i] ){

            prime[cnt++] = i << 1|1;

            }

            

    }

}

int Solve(  )

{

    int ans = 1,c[10000] = {0};

    for( int i = 0 ; i < 10 ; i ++ )

    {

           for( int j = 0 ; j < cnt  ; j ++ )

           {

            if( prime[j] > num[i] ) break;

            while( num[i] % prime[j] == 0 )

            {

                  c[prime[j]] ++;

                  num[i]/=prime[j];    

            }

        }

    }    

    for( int i = 1 ; i < 10000 ; i ++ )

          if(c[i]!=0)

          ans*=( c[i] + 1 );

   return ans%10;

}

int main(  )

{

    Prime();

    while( scanf( "%d",&num[0] )==1 )

    {

        for( int i = 1 ; i < 10 ; i ++ )

             scanf( "%d",&num[i] );

        printf( "%d\n",Solve(  ) );    

    }

    //system( "pause" );

    return 0;

}

 

你可能感兴趣的:(poj)