2415
# Include <stdio. h>
Int main ()
{
Int S1, n, m, S, J, I, II;
Scanf ("% d", & S1 );
While (S1 --)
{S = 0;
Scanf ("% d", & N, & M );
For (I = 1; I <= N; I ++)
{II = I;
If (II % m = 0)
{
S ++; II = II/m;
While (II % m = 0)
{
S ++; II = II/m;
}
}
}
Printf ("% d \ n", S );
}
}
# Include <iostream>
Using namespace STD;
Int main ()
{
Int m, n, k, S, sum;
Cin> S;
While (s --)
{
Sum = 0;
Cin> N> m; // M is a prime number.
While (N)
{
K = N/m;
Sum + = K;
N = K;
}
Cout <sum <Endl;
}
}
// Factorial decomposition. I thought it would be n! The number of M in all factorial values.
// This is not the original meaning.
// The description of the question is incorrect.
// 100/5 = 20 5
// 20/5 = 4 5
// 4/5 = 0 5
// End
// 20 + 4 + 0 = 24
**************************************** ***********
8 *************************************** **************************************** ******
# Include <stdio. h>
Int main ()
{
Int count, n, m, I, ii, T;
Scanf ("% d", & T );
While (t --)
{
Count = 0;
Scanf ("% d", & N, & M );
For (I = 1; I <= N; I ++)
{II = I;
If (II % m = 0) // check one by one
{
Count ++; // + 1
II = II/m; // whether the new II contains a certain power of m
While (II % m = 0) // a power of m
{Count ++; II = II/m ;}//
}
}
Printf ("% d", count );
}
}