【HDU】9437Lucky Number-(暴力构造)

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


 

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

2014 Multi-University Training Contest 7

 

Recommend

We have carefully selected several similar problems for you:  6460 6459 6458 6457 6456 

题目大意:将3,4,5,6认为是幸运数字。给定一个十进制数n。现在可以讲起任意转换成其他进制,但转换后的数必须是由3,4,5,6构成的,而这个进制称为幸运进制。问有多少个幸运进制。若有无数个,则输出-1。

思路:如果可以分解为2位x进制的数,那么就是 n=i*x+j;如果这个方程有整数解且这个x还要大于i和j,因为i进制的数是不会出现i即i以上的数字的,三位的就列出一个n=a*x*x+b*x+c的式子,解出方程,不要负的,判断就可以了,之后的就直接暴力判断就行了,进制x最大也不会x^3>n,不然就会变成上述三种的形式。我们就可以枚举进制然后判断是否为幸运进制了

代码:

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef __int64 LL;
LL Max(LL a, LL b,LL  c)
{
    return max(a, max(b, c));
}
int main()
{
    int T, cas = 0;
    LL n, i, j, k, a, b, c, derta, x, t;
    scanf("%d",&T);
    while(T--)
    {
        LL ans = 0;
        scanf("%I64d",&n);
        printf("Case #%d: ", ++cas);
        if(n >= 3 && n <= 6)
        {
            printf("-1\n");
            continue;
        }
        for(i = 3; i <= 6; i++)
        {
            for(j = 3; j <= 6; j++)    //两位时候,
            {
                if((n - i) % j == 0 && (n - i) / j > max(i, j))
                    ans++;
            }
        }
        for(i = 3; i <= 6; i++)  //三位时候
        {
            for(j = 3; j <= 6; j++)
            {
                for(k = 3; k <= 6; k++)
                {
                    a = i;
                    b = j;
                    c = k - n;
                    derta = (LL)sqrt(b * b - 4 * a * c + 0.5);
                    if(derta * derta != (b * b - 4 * a * c))
                        continue;
                    if((derta - b) % (2 * a))
                        continue;
                    x = (derta - b) / (2 * a);
                    if(x > Max(i, j, k))
                        ans++;
                }
            }
        }
        for(i = 4; i * i * i <= n; i++)
        {
            t = n;
            while(t)
            {
                if(t % i < 3 || t % i > 6)
                    break;
                t = t / i;
            }
            if(!t)
                ans++;
        }
        printf("%I64d\n", ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/wentong_Xu/article/details/86571520