We know what a base of a number is and what the properties are. For example, we use decimal number system, where the base is 10 and we use the symbols - {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. But in different bases we use different symbols. For example in binary number system we use only 0 and 1. Now in this problem, you are given an integer. You can convert it to any base you want to. But the condition is that if you convert it to any base then the number in that base should have at least one trailing zero that means a zero at the end.
For example, in decimal number system 2 doesn't have any trailing zero. But if we convert it to binary then 2 becomes (10)2 and it contains a trailing zero. Now you are given this task. You have to find the number of bases where the given number contains at least one trailing zero. You can use any base from two to infinite.
Input
Input starts with an integer T (≤ 10000), denoting the number of test cases.
Each case contains an integer N (1 ≤ N ≤ 1012).
Output
For each case, print the case number and the number of possible bases where N contains at least one trailing zero.
Sample Input
3
9
5
2
Sample Output
Case 1: 2
Case 2: 1
Case 3: 1
Note
For 9, the possible bases are: 3 and 9. Since in base 3; 9 is represented as 100, and in base 9; 9 is represented as 10. In both bases, 9 contains a trailing zero.
这个题思考一下就可以转化为公约数的题,就是找一下一共有几个公约数(不包括1,没有1进制- -),有一个公式,
就用这个公式算一下因子的个数然后减1,(因为不包括1)
还有一点需要注意我写在代码里。
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cmath>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll;
const int maxn=1010000;
ll primer[maxn];
ll ea[maxn],cnt=1;
void isprimer()
{ memset(ea,0,sizeof(ea));
for(int i=2;i<=maxn;i++)
{
if(ea[i]==0)
{ primer[cnt++]=i;
for(ll j=i*2;j<maxn;j+=i)
{
ea[j]=1;
}
}
}
}
int main()
{ int T;
cin>>T;
ll a,i=1;
ll sum=0;
isprimer();
ll time=1;
while(T--)
{
scanf("%lld",&a);
ll sum=1,sum1=0;
for(i=1;i<cnt && primer[i]*primer[i]<=a;i++) // 相当于 i<=sqrt(a) 算到sqrt就可以
{
sum1=0;
while(a%primer[i]==0)
{
a=a/primer[i];
sum1++;
}
sum=sum*(sum1+1);
}
if(a>1) sum=sum*2; //如果说算到最后n仍然大于1的话,就是剩下一个质数他的次数是1,所以
//说再乘以一个(1+1)就可以了。
cout<<"Case "<<time++<<": "<<sum-1<<endl;
}
return 0;
}