Code: Select all
u32CatsPerHat = (uint32)(dCatsPerHat + .0001);
Moderator: Board moderators
Code: Select all
u32CatsPerHat = (uint32)(dCatsPerHat + .0001);
Code: Select all
#include<iostream.h>
int prime[25]={
2,3,5,7,11,
13,17,19,23,29,
31,37,41,43,47,
53,59,61,67,71,
73,79,83,89,97
};
int main(){
unsigned long int l,wc,N,I,nwc,sl,k,i;
while(1){
unsigned long int occ[25]={0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0
};
cin>>l>>wc;
if((l==0)&&(wc==0)) return 0;
if(l==1){
cout<<0<<1<<endl;
continue;
}
k=wc;
for(i=0;i<25;i++){
while(k%prime[i]==0){
occ[i]++;
k/=prime[i];
}
}
N=1;
for(i=0;i<25;i++)
if(occ[i]){
I=occ[i];
N*=prime[i];
}
while((l%(N+1))){///this
N*=N;
I/=2;
} ///this
nwc=1;
k=1;
for(i=1;i<I;i++){
k*=N;
nwc+=k;
}
sl=l;
unsigned long int l2=l;
k=N;
for(i=1;i<I+1;i++){
l2/=(N+1);
sl+=(k*l2);
k*=N;
}
cout<<nwc<<" "<<sl<<endl;
}
return 0;
}
Code: Select all
1 1
100 1
1000 1
10000 1
216 125
5764801 1679616
1024 243
2 1
4 1
1024 1
371293 248832
11 10
1 1
1048576 59049
483736625 481890304
125 64
1 0
64 1
0 0
Code: Select all
0 1
7 199
10 1999
13 19999
31 671
335923 30275911
121 3367
1 3
2 7
10 2047
22621 1840825
1 21
0 1
29524 4017157
615441 1931252289
21 369
1 1
6 127
Code: Select all
#include <math.h>
#include <stdio.h>
#define maxLayer 32
int main ( void )
{
unsigned long initialHeight , numOfSmallestCat , numOfSmallerCat , layer , result1 , result2 , i ;
double catPerHat , epsilon = ( double ) 0.0001 ;
/*freopen ( "107.in" , "r" , stdin ) ;
freopen ( "107.out" , "w" , stdout ) ;*/
while ( scanf ( "%lu %lu" , &initialHeight , &numOfSmallestCat ) != EOF )
{
if ( initialHeight == 0 && numOfSmallestCat == 0 ) break ;
if ( initialHeight == 1 ) printf ( "0 %d\n" , numOfSmallestCat) ;
else
{
for ( layer = 1 ; layer <= maxLayer ; layer ++ )
{
catPerHat = pow ( numOfSmallestCat , ( double ) 1.0 / layer ) ;
if ( catPerHat - floor ( catPerHat ) > epsilon ) continue ;
if ( fabs ( pow ( catPerHat + 1 , layer ) - initialHeight ) < epsilon ) break ;
}
numOfSmallerCat = floor ( catPerHat ) ;
if ( numOfSmallerCat == 1 ) result1 = layer ;
else result1 = ( pow ( numOfSmallerCat , layer ) - 1 ) / ( numOfSmallerCat - 1 ) ;
result2 = 0 , i = 1 ;
do
{
result2 += i * initialHeight ;
if ( initialHeight == 1 ) break ;
initialHeight /= ( numOfSmallerCat + 1 ) ;
i = i * numOfSmallerCat ;
}
while ( 1 ) ;
printf ( "%lu %lu\n" , result1 , result2 ) ;
}
}
return 0 ;
}