HDU 4937 Lucky Number

原创 2015年11月18日 23:41:51


Lucky Number

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


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.


题意:输入一个十进制数字n,用一个k进制数表示,每个数只能包含3 4 5 6,问这样的k有多少个

#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

typedef long long ll;
int main()
{
    int T;
    scanf("%d",&T);
    for(int ca=1;ca<=T;ca++)
    {
        ll n;
        scanf("%I64d",&n);
        printf("Case #%d: ",ca);

        if(n>=3&&n<=6)//只有3 4 5 6是无限多种进制可以表示,10以上数字会用'A'表示
        {
            puts("-1");
            continue;
        }

        int num=0;
        for(int i=3;i<=6;i++)//两位的时候
            for(int j=3;j<=6;j++)
            {
                if((n-j)%i==0 && (n-j)/i>i && (n-j)/i>j)
                {
                    num++;
                }
            }

        for(int i=3;i<=6;i++)//三位组成的时候
            for(int j=3;j<=6;j++)
                for(int k=3;k<=6;k++)
                {
                    ll m=j*j-4*(k-n)*i;
                    ll f=sqrt(m);
                    if(f*f==m)
                    {
                        ll tt=(f-j)%(2*i);
                        ll ff=(f-j)/(2*i);
                        if(tt==0 && ff>i && ff>j && ff>k)
                        {
                            num++;
                        }

                    }
                }

        for(int i=4;i<=10000;i++)//大于等于四位的时候,此时进制数最大不会超过10000
        {
            ll t=n;
            int flag=0;
            int cnt=0;
            while(t)
            {
                ll f=t%i;
                if(f<3 || f>6)
                {
                    flag=1;
                    break;
                }
                t/=i;
                cnt++;//判断有几位,小于4位前面已经出现过,会重复
            }

            if(flag==0 && cnt>3)
            {
                num++;
            }
        }

        printf("%d\n",num);
    }
    return 0;
}






相关文章推荐

hdu 4937 Lucky Number 科学暴力

Lucky Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

HDU 4937 Lucky Number 【搜索】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4937 搜索 机智的暴力

【HDU4937】Lucky Number(模拟)

比较简单的题。。。又没做出来T^T

HDU 4937 (杭电多校 #7 1003题)Lucky Number(瞎搞)

题目地址:HDU 4937 多校的题以后得重视起来。。。每道题都错好多次。。。很考察细节。比如这道。。。。WA了无数次。。。。 这题的思路自己真心想不到。。。这题是将进制后的数分别是1位,2位,3...

HDU-4937-Lucky Number

这个题比赛的时候没做出来,本来以为枚举时间不多(我开始用的DFS+各种

hdu4937 Lucky Number,数论

hdu4937 Lucky Number 比较简单的数论题。 把n分别减去3 4 5 6,剩下的为tn。 求出tn的所有约数,尝试所有约数是否满足基的条件即可。这样复杂度只有O(sqrt(n))...

HDU4937:Lucky Number

Problem Description “Ladies and Gentlemen, It’s show time! ” “A thief is a creative artist who...

hdu 4937 Lucky Number(数学题 进制转换)2014多校训练第7场

Lucky Number                                                                          Time Limit: 20...

hdoj 4937 Lucky Number【想法】

题目:hdoj 4937 Lucky Number 来源:2014 Multi-University Training Contest 7 分类:想法题 题意;给出一...

hdoj4937Lucky Number

Lucky Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:HDU 4937 Lucky Number
举报原因:
原因补充:

(最多只允许输入30个字)