当进制转换后所剩下的为数较少时(2位。3位),相应的base都比較大。能够用数学的方法计算出来。

预处理掉转换后位数为3位后,base就小于n的3次方了,能够暴力计算。

。。

Lucky Number

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

Total Submission(s): 521    Accepted Submission(s): 150

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
 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <cmath> using namespace std; typedef long long int LL; LL n;
set<LL> ans;
bool change(LL x,LL base)
{
bool flag=true;
while(x)
{
LL temp=x%base;
x/=base;
if(temp>=3LL&&temp<=6LL) continue;
else
{
flag=false;
break;
}
}
return flag;
} int main()
{
int T_T,cas=1;
scanf("%d",&T_T);
while(T_T--)
{
ans.clear();
cin>>n;
if(n>=3LL&&n<=6LL)
{
cout<<"Case #"<<cas++<<": -1"<<endl; continue;
} for(LL a=3;a<=6;a++)
{
for(LL b=3;b<=6;b++)
{
LL limit=max(a,b);
if( (n-b)%a == 0 )
{
if( (n-b)/a > limit)
{
ans.insert((n-b)/a);
}
}
}
} for(LL a=3;a<=6;a++)
{
for(LL b=3;b<=6;b++)
{
for(LL c=3;c<=6;c++)
{
LL C=c-n;
if(b*b >= 4LL*a*C )
{
LL deta=sqrt(b*b-4LL*a*C);
LL base1=(-b+deta)/(2*a);
LL base2=(-b-deta)/(2*a);
LL limit=max(a,max(b,c));
if(a*base1*base1+b*base1+c==n && base1>limit)
{
ans.insert(base1);
}
if(a*base2*base2+b*base2+c==n && base2>limit)
{
ans.insert(base2);
}
}
}
}
} for(LL i=4;i*i*i<=n;i++)
{
if(change(n,i))
{
ans.insert(i);
}
}
cout<<"Case #"<<cas++<<": "<<ans.size()<<endl;
}
return 0;
}

HDOJ 4937 Lucky Number的更多相关文章

  1. 枚举 + 进制转换 --- hdu 4937 Lucky Number

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

  2. HDU 4937 Lucky Number(2014 Multi-University Training Contest 7)

    思路:先枚举  a*bas +b = n  求出 bas 在sqrt(n)到n的  (bas>a&&bas>b) 再枚举  a*bas*bas+b*bas+c =n  求出 ...

  3. HDU 4937 Lucky Number (数学,进制转换)

    题目 参考自博客:http://blog.csdn.net/a601025382s/article/details/38517783 //string &replace(iterator fi ...

  4. 2014多校第七场1003 || HDU 4937 Lucky Number

    题目链接 题意 : 给定一个十进制n,让你转化成某个进制的数,让这个数只包含3 4 5 6这些数字,这个进制就成为n的幸运数字,输出有多少幸运数字,例如19,5进制表示是34,所以5是19的一个幸运数 ...

  5. hdu 4937 Lucky Number

    虽然算法清晰的不能再清晰,但是实现总是边角料错这错那. 题目大意: 给出n,找出一些进制,使得n在该进制下仅为3,4,5,6表示 解题思路: 首先,4-10000进制直接枚举计算出每一位 此外,最多只 ...

  6. HDU 4937 Lucky Number 规律题_(:зゝ∠)_

    把全部合法的进制打出来会发现合法的进制都是在 n/3 n/4 n/5的边上 然后暴力边上的进制数.. #include <cstdio> #include <set> type ...

  7. HDU 4937 Lucky Number 搜索

    题意: 给你一个数,求在多少种不同的进制下这个数每一位都是3.4.5.6中的一个. 思路: 搜索.枚举这个数在任意进制下的表示,判断是否合法.当数字只有3.4.5.6时,必定有无穷种. 因为数字太大, ...

  8. 水题 HDOJ 4727 The Number Off of FFF

    题目传送门 /* 水题:判断前后的差值是否为1,b[i]记录差值,若没有找到,则是第一个出错 */ #include <cstdio> #include <iostream> ...

  9. SCU3502 The Almost Lucky Number

    Description A lucky number is a number whose decimal representation contains only the digits \(4\) a ...

随机推荐

  1. Find命令简介

    Find命令主要用于目标的搜索,尽量做到少使用,因为find会消耗大量的系统资源. 使用该命令时,需要避开服务器运行高峰期,最好在指定的小范围内进行搜索,不要轻易使用全盘搜索. Find命令常用的参数 ...

  2. 颜色矩阵 滤镜 ColorMatrix

    颜色矩阵原理 色彩的三要素 1.色相.色相通俗的说就是"颜色",色相的改变就是颜色的改变,色相的调节伴随着红橙黄绿蓝紫的变化. 2.亮度.明度通俗的说就是"光照度&quo ...

  3. 【回顾整理】HTML+CSS个的两个实战项目

    一:麦子商城首页制作 代码: <!DOCTYPE html> <html> <head lang="en"> <meta charset= ...

  4. DataGrid 简单数据绑定实例1

    1.默认数据显示(自动显示列) 后台绑定 //DataGrid 数据绑定 dataGridOne.ItemsSource = _Context.Info.ToList(); 前台定义 <Data ...

  5. 小技巧之jQueryMobile

    使用JqueryMobile+MVC做一个手机网站,也有2个月了.有一些小小的经验,跟大伙们分享一下下 小技巧1: 禁用所有Ajax加载,它会很烦人的. $.mobile.ajaxLinksEnabl ...

  6. 如何快速恢复MyEclipse的默认主题

    这里天在研究主题,到网上找了一些主题导入,可是有一部分主题导入后不能通过preference选项进行恢复默认主题!那怎么办?有没有别的办法! 在网上找了一些答案,有更改工作空间的办法,也有替换.set ...

  7. WINDOWS系统下环境变量PATH和CLASSPATH的意思

    1 PATH 对于没有包含路径的命令,WINDOWS系统会默认去Windows 目录(C:\windows)和系统目录(C:\windows\system32)查找,如果没有找到,就去PATH变量内包 ...

  8. C#多线程实践——锁和线程安全

    锁实现互斥的访问,用于确保在同一时刻只有一个线程可以进入特殊的代码片段,考虑下面的类: class ThreadUnsafe { static int val1, val2; static void ...

  9. 乱七八糟Nodejs系列二:线程模型

    上一篇中说了这样一句话:Nodejs和浏览器javascript一样,都是单线程,所以和传统的不一样,这个后面有机会再说.挖了坑就得填,哎. 1.一个例子 来看一个例子,这个例子来自async jav ...

  10. 编写自己的javascript功能库之Ajax(仿jquery方式)

    本人学习的是php,所以就用php跟js来演示代码了,主要是锻炼自己写js的能力,练练手而已. 下面这是我编写的操作ajax的代码功能,勉强让我称之为库吧.. js代码实例(tool.ajax.js) ...