LightOJ 1028 Trailing Zeroes (I)

来源:互联网 发布:flash网站源码 编辑:程序博客网 时间:2024/06/11 06:27

Description

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

Hint

For 9, the possible bases are: 3 and 9. Since in base 39 is represented as 100, and in base 99 is represented as 10. In both bases, 9 contains a trailing zero.



题意:求一个数n,有多少种进制表示方法,使得末尾为0. 

题解:一个数转换成n进制之后,若末尾为0,则该数必定被n整除。
所以该题就是求输入数的约数(因数)个数。
打表找出10^6以内的素数,然后枚举素数。除此之外还要用prime[i]*prime[i]<=n限制。

最终求得的个数要减1,因为这其中包括1这个因数,而1不满足条件


#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <queue>#include <vector>#include <cmath>#include <stack>#include <string>#include <sstream>#include <map>#include <set>#define pi acos(-1.0)#define LL long long#define ULL unsigned long long#define inf 0x3f3f3f3f#define INF 1e18#define lson l,mid,rt<<1#define rson mid+1,r,rt<<1|1#define debug(a) printf("---%d---\n", a)#define mem0(a) memset(a, 0, sizeof(a))#define memi(a) memset(a, inf, sizeof(a))#define mem1(a) memset(a, -1, sizeof(a))using namespace std;typedef pair<int, int> P;const double eps = 1e-10;const int maxn = 1e6 + 5;const int mod = 1e8;LL prime[maxn], vis[maxn];int cnt = 0;void chart(){memset(vis, 0, sizeof(vis));vis[1] = 1;for (int i = 2; i < maxn; i++){if (vis[i]) continue;prime[++cnt] = i;for (int j = 2; j * i < maxn; j++)vis[j * i] = 1;} }int main(void){//freopen("in.txt","r", stdin);chart();LL T, n, ans, cas = 0;cin >> T;while (T--){cin >> n;ans = 1;for (int i = 1; i <= cnt && prime[i]*prime[i] <= n; i++){// 要用prime[i]*prime[i] <= n优化 不然会超时 LL t = 0;while (n % prime[i] == 0){n /= prime[i];t++;}ans *= (t + 1);}if (n > 1) ans *= 2;cout << "Case " << ++cas << ": " << ans - 1 << endl;}return 0;}


0 0