hdoj4937Lucky Number

Lucky Number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1582    Accepted Submission(s): 459


Problem Description
“Ladies and Gentlemen, It’s show time! ”

“A thief is a creative artist who takes his prey in style... But a detective is nothing more than a critic, who follows our footsteps...”

Love_Kid is crazy about Kaito Kid , he think 3(because 3 is the sum of 1 and 2), 4, 5, 6 are his lucky numbers and all others are not. 

Now he finds out a way that he can represent a number through decimal representation in another numeral system to get a number only contain 3, 4, 5, 6. 

For example, given a number 19, you can represent it as 34 with base 5, so we can call 5 is a lucky base for number 19. 

Now he will give you a long number n(1<=n<=1e12), please help him to find out how many lucky bases for that number. 

If there are infinite such base, just print out -1.
 

Input
There are multiply test cases.

The first line contains an integer T(T<=200), indicates the number of cases. 

For every test case, there is a number n indicates the number.
 

Output
For each test case, output “Case #k: ”first, k is the case number, from 1 to T , then, output a line with one integer, the answer to the query.
 

Sample Input
  
  
2 10 19
 

Sample Output
  
  
Case #1: 0 Case #2: 1
Hint
10 shown in hexadecimal number system is another letter different from ‘0’-‘9’, we can represent it as ‘A’, and you can extend to other cases.
 

Author
UESTC
 

Source
 

题意:给你一个数n判断是否存在k进制使得在k进制下只用3,4,5,6,表示n

解题思路:当在k进制下能表示成n如果此时k进制下n的个数等于2是直接暴力这两位数;如果k进制下n的个数等于3直接暴力这3位数。如果k进制下n的位数大于3则直接枚举从2到sqrt(n)进制暴力求解

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
using namespace std;
const int maxn=1010;
int getnum(long long num){
	int ans=0;
	while(num){
		num/=10;
		ans++;
	}
	return ans;
}
int main()
{
	int t,test=1;
	long long n,i,j,k;
	scanf("%d",&t);
	while(t--){
		scanf("%lld",&n);
		printf("Case #%d: ",test++);
		if(n==3||n==4||n==5||n==6){
			printf("-1\n");
		}
		else {
			int ans=0;
			for(i=3;i<=6;++i){
				for(j=3;j<=6;++j){
					if((n-j)%i==0){
						if(((n-j)/i)>i&&((n-j)/i)>j)ans++;
					}
				}
			}
			for(i=3;i<=6;++i){
				for(j=3;j<=6;++j){
					for(k=3;k<=6;++k){
						long long c=k-n;
						if((j*j-4*i*c)<0)continue;
						long long d=sqrt(j*j-4*i*c);
						if(d*d!=(j*j-4*i*c))continue;
						if(((d-j)%(2*i))!=0)continue;
						long long x=(d-j)/(2*i);
						if(x>i&&x>j&&x>k)ans++;
					}
				}
			}
			for(i=2;i*i*i<=n;++i){
				long long m=n;
				while(m){
					if(m%i!=3&&m%i!=4&&m%i!=5&&m%i!=6)break;
					m/=i;
				}
				if(!m)ans++;
			}
			printf("%d\n",ans);
		}
	}
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值