LightOJ 1028 1028 - Trailing Zeroes (I) (求因子个数)

1028 - Trailing Zeroes (I)
Time Limit: 2 second(s)Memory Limit: 32 MB

We know what a base of a number is and what the propertiesare. For example, we use decimal number system, where the base is10 andwe use the symbols - {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. But in differentbases we use different symbols. For example in binary number system we use only0 and1. Now in this problem, you are given an integer. You canconvert it to any base you want to. But the condition is that if you convert itto any base then the number in that base should have at least one trailing zerothat means a zero at the end.

For example, in decimal number system 2 doesn't haveany trailing zero. But if we convert it to binary then2 becomes (10)2and it contains a trailing zero. Now you are given this task. You have to findthe 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 ofpossible bases where N contains at least one trailing zero.

Sample Input

Output for Sample Input

3

9

5

2

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 as100, and in base 9;9 is represented as10. In both bases, 9 contains atrailing zero.


题意:求n的因子个数


思路:根据公式即可求出,和这道题(点击打开链接)差不多。。刚开始以为简单写不会超时,写完后TLE,没办法,打个素数表优化一下吧。。


ac代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stack>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#define MAXN 1010100
#define LL long long
#define ll __int64
#define INF 0x7fffffff
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-10
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
//head
int prime[MAXN];
int v[MAXN];
int cnt;
void db()
{
	mem(v);
	cnt=0;
	int i,j;
	for(i=2;i<MAXN;i++)
	{
		if(!v[i])
		{
			prime[cnt++]=i;
			for(j=i*2;j<MAXN;j+=i)
			v[j]=1;
		}
	}
}
int main()
{
	db();
    int t,i,j,a;
    LL n;
    int cas=0;
    scanf("%d",&t);
    while(t--)
    {
    	scanf("%lld",&n);
    	LL ans=1;
    	for(i=0;i<cnt&&prime[i]*prime[i]<=n;i++)
    	{
    		if(n%prime[i]==0)
    		{
    			int ccnt=0;
    			while(n%prime[i]==0)
    			{
    				ccnt++;
    				n/=prime[i];
				}
				ans=ans*(ccnt+1);
			}
		}
		if(n>1)
		ans*=2;
		printf("Case %d: ",++cas);
		printf("%lld\n",ans-1);
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值