hdu 4937 Lucky Number 科学暴力

Lucky Number

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


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
 


思路:论科学的暴力的重要性。首先对于inf这种情况,一定是n=3,4,5,6,因为对于大于n的base,化为进制数还是由3,4,5,6组成的。

    对于a1*x+a0这种形式的,枚举a1,a0,共16种情况。

   对于a2*x^2+a1*x+a0这种形式,枚举a2,a1,a0,g共64种情况,解二次方程判断是否存在符合进制。

   对于含有x三次方及其以上的,直接从4暴力枚举到1e4,看是否有可行的进制,详见代码:

// file name: 3.cpp //
// author: kereo //
// create time:  2014年08月12日 星期二 19时43分48秒 //
//***********************************//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN=10000+100;
#define L(x) (x<<1)
#define R(x) (x<<1|1)
ll n;
int main()
{
    int T,kase=0;
    scanf("%d",&T);
    while(T--){
        scanf("%I64d",&n);
        printf("Case #%d: ",++kase);
        if(n>=3 && n<=6){ 
            printf("-1\n");
            continue;
        }
        ll ans=0;
        for(ll i=3;i<=6;i++)
            for(ll j=3;j<=6;j++){
                if((n-i)%j == 0 && (n-i)/j >max(i,j))
                    ans++;
            }
        for(ll i=3;i<=6;i++)
            for(ll j=3;j<=6;j++)
                for(ll k=3;k<=6;k++){
                    ll a=i,b=j,c=k-n;
                    ll d=(ll)sqrt(b*b-4*a*c+0.5);
                    if(d*d!=b*b-4*a*c)
                        continue;
                    if((d-b)%(2*a))
                        continue;
                    ll x=(d-b)/(2*a);
                    if(x>max(i,max(j,k)))
                        ++ans;
                }
        for(ll i=4;i*i*i<=n;i++){
            ll x=n;
            while(x){
                if(x%i<3 || x%i >6)
                    break;
                x/=i;
            }
            if(!x)
                ans++;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值