Lucky Number

“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

题意:

输入一个十进制数N,把他转换成其他任意进制数,如果转换之后的某进制数中,所有的数字都属于集合(3,4,5,6)(每个数字都可以出现任意次数),那么记录下此时的基数(不用保存,不用输出),结果+1 。输出符合条件的基数的总个数(如果这样的基数有无限个,则输出-1).例如19在5进制下是34,所以5是幸运进制

思路:

枚举时,考虑进制的基数最大枚举 1e4 。

AC代码:

#include <cstdio>   //AC  g++  15ms
#include <cmath>
#include <algorithm>
using namespace std;int main()
{int T;scanf("%d",&T);int tt=0;while(T--){long long int value;scanf("%lld",&value);if(3 <= value && value <= 6){printf("Case #%d: -1\n",++tt);}else{   //下面开始讨论三种 情况long long int ans = 0;long long int i,j,k;    //因为 基数可能很大for(i=3;i<=6;i++){  //value = i* x + j (x是进制基数)for(j=3;j<=6;j++){      // 即 基数 x > 任何一位上面的数字if( (value-j)%i==0 && (value-j)/i > max(i,j))++ans;}}long long int d,x,c;for(i=3;i<=6;i++){  //value = i*x^2 + j*x + k;for(j=3;j<=6;j++){for(k=3;k<=6;k++){  //!!! 我的天!用公式求根,前提是 0 = i*x^2 + j*x + C 啊啊啊c = k-value;    //!!!就是这个位置d = (long long int)sqrt(j*j-4*i*c+0.5);if(d*d != (j*j-4*i*c) ) //判断代尔塔 要是整数continue;if( (-j+d)%(2*i)!=0)continue;x = (-j+d)/(2*i);   //要确保 x 的值是 正整数(所以去掉-j-d)if(x > max(i,max(j,k)))++ans;}}}long long int t;for(i=2; i*i*i<=value; i++){ //排除 1 (不然,是死循环)t  = value;while(t != 0){if((t%i < 3) || (t%i > 6) )break;t = t/i;    //若没有break,说明本次处理结果符合标准}if(t == 0)  //说明除尽才退出的(所以,记录i )++ans;}//   printf("Case #%d: %I64d\n",++tt,ans); //在VJ 上面用g++ 提交,都对printf("Case #%d: %lld\n",++tt,ans);}}return 0;
}

学习代码:http://blog.csdn.net/a601025382s/article/details/38517783

HDU 4937Lucky Number相关推荐

  1. HDU 1005 Number Sequence

    [题目]                                                   Number Sequence Time Limit: 2000/1000 MS (Jav ...

  2. HDU 4054 Number String

    HDU 4054 Number String 思路: 状态:dp[i][j]表示以j结尾i的排列 状态转移: 如果s[i - 1]是' I ',那么dp[i][j] = dp[i-1][j-1] + ...

  3. HDU.1005 Number Sequence

    原题 HDU.1005 Number Sequence 分类 杂题 题意 给定一个数列{an}\left\{ a_n \right\}{an​}的前两项a1a_1a1​.a2a_2a2​,以及其递推公 ...

  4. HDU 1711 Number Sequence(KMP算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Number Sequence Time Limit: 10000/5000 MS (Java/ ...

  5. HDU 1711 -Number Sequence(KMP)

    题目 Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  6. HDU 1711 Number Sequence(KMP模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1711 这道题就是一个KMP模板. 1 #include<iostream> 2 #include&l ...

  7. hdu 4279 Number (找规律)

    http://acm.hdu.edu.cn/showproblem.php?pid=4279 题意: 给出a,b两个数,1<=a<=b 如果a,b不互质,且a%b != 0则说明a是b的特 ...

  8. hdu 1711 Number Sequence

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 题目大意:在母链中找到子链的位置,输出开始的位置. 1 #include <iostrea ...

  9. HDU 1005 — Number Sequence

    原题:http://acm.hdu.edu.cn/showproblem.php?pid=1005 思路: 找规律: 当出现两个1 时即找到了循环点:因为f[n]和f[n-1].f[n-2]有关,所以 ...

最新文章

  1. Android Studio cannot find declaration to go to
  2. 1833: [ZJOI2010]count 数字计数
  3. DZ各个数据表详解(DZ论坛各表详细说明,二次开发用)
  4. NYOJ 115 城市平乱(图论Dijkstra)
  5. 修改bootstrap modal模态框的宽度
  6. Java EE 6 Web配置文件。 在云上。 简单。
  7. 隐马尔科夫模型(Hidden Markov Models) 系列之一
  8. C语言-字符数组和字符串
  9. flash计算机硬件,实测Flash在硬件加速下的对比
  10. Android显示人民币双横线的¥符号
  11. Carrey的第一篇博客
  12. Trinity安装全过程并解决部分报错
  13. java案例之制作系统
  14. 使用Jquery、HTML、CSS、JS实现下拉菜单列表
  15. linux错误码分析
  16. ecshop linux,Linux中Ecshop搭建
  17. java applet编程_第二十讲 Java Applet程序设计
  18. 解决VA加载失败问题:visual assist ({44630D46-96B5-488C-8DF9-26E21DB8C1A3})未加载。请与程序包供应商联系以获得帮助
  19. 使用U盘安装CentOS 8.2(3)将CentOS写入U盘要使用RAW方式
  20. 计算机三员培训个人总结,信息技术培训个人工作总结

热门文章

  1. find命令中参数perm的用法
  2. javaweb邮箱页面架构
  3. tl494cn逆变器电路图_TL494制作的400W大功率稳压逆变器电路图
  4. 新古典增长理论和内生增长理论的小总结
  5. 时钟 主频 分频 倍频 预分频 后分频
  6. 计算机模拟试题十及答案
  7. 【二维码】二维码生成
  8. U3D_关于UI中的锚点
  9. iOS小技能:-fobjc-arc和 -fno-objc-arc 的使用(在非ARC工程中集成ARC代码、在ARC工程中集成非ARC的第三方代码)
  10. 关于速度与时间的关系