Trailing Zeroes (I) LightOJ - 1028

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.

#include <cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;

const int maxn=1e6+10;
ll prime[maxn];
int vis[maxn],cnt=0;

void init()
{
    ll i,j,k;
    cnt=0;
    memset(vis,0,sizeof(vis));
    for(i=2;i<maxn;i++)
    {
        if(!vis[i])
        {
            for(j=i*i;j<maxn;j+=i)
            vis[j]=1;
            prime[cnt++]=i;
        }
    }
}

/*
The essence is to reduce the val value every time, so as to reduce the number of i enumerated, which has been Tle before.
*/

intmain()
{
    init();
    int T, kase = 1;
    scanf("%d",&T);
    while(T--){
        ll val,cval,ans=1,tmp;
        scanf("%lld",&val);
        for(int i=0;i<cnt&&prime[i]*prime[i]<=val;i++){
            if(val%prime[i]==0){
                tmp=0;
                while(val%prime[i]==0){
                    tmp++;
                    val/=prime[i];
                }
                ans*=(tmp+1);
            }
        }
        if(val!=1)ans*=2;
        printf("Case %d: %lld\n",kase++,ans-1);
    }
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325996103&siteId=291194637