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

题意:t 组数据,每组给出一个十进制数 n,现可将其转为任意进制,但要求转换后的数只由 3、4、5、6 构成的,问满足条件的进制有几种,若有无数个,则输出 -1

思路: 对于任何一种进制 x,均满足 n=A0+A1*x+A2*x^2+A3*x^3+...,因此可对 n 转换后的进制位数进行分情况处理

  • 对于一位的情况,很明显有无穷个,即 -1
  • 对于两位的情况,有 n=A0+A1*x 的形式,枚举 A0、A1,判断是否有整数解 x,此外,还需判断 x 是否大于 A0、A1 的最大值
  • 对于三位的情况,有 n=A0+A1*x+A2*x^2,枚举 A0、A1、A2,判断是否有整数解 x,此外,还需判断 x 是否大于 A0、A1、A2 的最大值
  • 对于四位的情况,由于 n 最大为 1E12,此时最多也只有 7000 个数,而 7000^3 接近 1E12,因此直接枚举进制数来判断即可,不必考虑更多的可能

因此,可以枚举进制然后判断是否满足题设

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define PI acos(-1.0)
#define E 1e-6
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define N 1001
#define LL long long
using namespace std;
LL max(LL a,LL b,LL c){return max(a,max(b,c));
}
int main(){int t;scanf("%d",&t);int Case=1;while(t--){LL n;scanf("%lld",&n);LL res=0;if(n>=3&&n<=6){//一位的情况res=-1;}else{for(LL i=3;i<=6;i++){//两位的情况for(LL j=3;j<=6;j++){LL k=(n-j)/i;if(k*i==n-j&&k>max(i,j))res++;}}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 delta=b*b-4*a*c;if(delta>0){LL d=sqrt(delta);if(d*d==delta){LL x=(-b+d)/(2*a);if(x>max(i,j,k)&&x*2*a==(-b+d))res++;}}}}}for(LL i=2;i<=7000;i++){//四位的情况LL temp=n,bit;LL num=0;bool flag=true;while(temp){bit=temp%i;temp=temp/i;num++;if(bit<3||bit>6){flag=false;break;}}if(flag&&num>3)res++;}}printf("Case #%d: %lld\n",Case++,res);}return 0;
}

Lucky Number(HDU-4937)相关推荐

  1. oracle存小数用 number(m,n)

    oracle存小数用 number(m,n),m是长度,n是小数后几位数. 之前遇到了一个问题: 本来字段用的是单纯的number和varchear,保存整数用.后面要改成支持小数类型,但是表中已经有 ...

  2. Guess Number(Java版)

    Guess Number (Java版) 源代码下载地址如下 Guess Number源代码 游戏规则: 1.根据系统提示,请输入1~100范围以内的数,猜对结束,猜错继续. 2.系统会计时,没有时间 ...

  3. 有源汇有上下界最大流/最小流 配题(HDU 3157)

    因为是有源汇所以设源点为 s,汇点为 t. 有源汇有上下界最大流: 连接一条 t 指向 s 的边,容量为 INF. 通过上述步骤,现在图变成了无源汇网络. 引入超级源点 S,超级汇点 T. 连接一条 ...

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

    Lucky Number                                                                          Time Limit: 20 ...

  5. 最大表示法--环形字符串最大字典序(HDU 5442)

    http://acm.hdu.edu.cn/showproblem.php?pid=5442 问题概述:n个字符围成一个环,请从这个环中找出字典序最大的长度为n的字符串,输出它的起始点和方向(0顺1 ...

  6. S-Nim (HDU 1536)组合博弈SG多组游戏

    S-Nim 题目链接 Problem Description Arthur and his sister Caroll have been playing a game called Nim for ...

  7. 动态规划 求第 n 个 Humble Number(丑数)

    题目: 质因数分解是将一个数分解为若干个质数相乘的形式,这些因数可以重复.比如 30 = 2×3×5,20 = 2×2× 5,81 = 3×3×3×3.现在我们将质因数分解之后只出现 2,3,5,7 ...

  8. HDU2019多校第二场 1009(HDU 6599) I Love Palindrome String(回文树(自动机)+manacher)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6599 解题思路: 回文自动机求每个本质不同的子串出现的次数,同时记录每个节点i代表的回文串第一次出现的 ...

  9. Getfasta--根据Acession Number(Ac号)批量下载GenBank分子序列数据的自动化程序

    推断分子系统发育树时,很多分子序列数据都是从GenBank等公共数据库下载的.当数据很多时,每条序列都要检索.下载十分耗时,而且容易出错.作者基于NCBI官方提供的Entrez direct软件包,二 ...

最新文章

  1. 小米正用时序数据库,解决这个“硬核”问题
  2. 使用TESSERACT来识别字符
  3. 高cpu_实用脚本:检查高 CPU / 内存消耗进程 | Linux 中国
  4. MongoDB学习之(一)安装
  5. 开源播放器 支持视频广告
  6. 实施微服务应该具备哪些先决条件?
  7. 如何查看Windows 10的具体版本号?
  8. Iocomp控件 Iocomp安装教程 Crack 下载
  9. android adb 刷机工具,ADB 工具 ADB 工具刷机-完美教程资讯
  10. java实现解压war_java文件操作之war压缩解压
  11. 如何检查您的 Android 设备是否支持 Widevine DRM
  12. 正则表达式之提取数字
  13. 一年的网络学习经历小结
  14. Oracle AutoVue 运用场景及操作说明
  15. Docker - 单独搭建部署应用服务(Nginx+Php+Mysql+Redis)
  16. 拍七游戏(zzuli)
  17. Postman的应用——入门应用
  18. 斗破苍穹文字页游php_《斗破苍穹》在网文中的地位到底怎么样?
  19. 计算机语言,C语言!
  20. 计算机辅助设计绘图员技能鉴定试题(建筑类),计算机辅助设计绘图员(中级)技能鉴定试题(建筑类)A.doc...

热门文章

  1. CANOpen数据存档文件
  2. java 可选参数_超干货详解:kotlin(4) java转kotlin潜规则
  3. 新来个技术总监:谁在用isXxx形式定义布尔类型年后不用来了
  4. 阿里二面差点败在这道题:MySQL自增主键为何不是连续的呢?
  5. LinkedList作者说他自己都不用LinkedList?看完给我整不会了。。
  6. UEditor在线编辑器配置及注意事项
  7. 开发环境中Docker的使用
  8. 使用注解装配Bean
  9. Vue-cli(四) 项目中引入Axios
  10. saltstack grains