Lucky Number

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

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
 
Recommend
We have carefully selected several similar problems for you:  4944 4943 4942 4941 4940 
 
题意、题解,转自:
 

题意:

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

题解:

先考虑特殊情况,所情况下会有无穷个?只有n=3,4,5,6的时候,因为这几个数在大于n的进制下都是他本身。。注意特殊情况不包括33,343这些(我一开始就死在这里了,wa了三次)。因为33在34进制下就不是33了(类似于10在16进制下就是A了)。

我们知道n=a0+a1*x+a2*x^2+...,其中x为进制。由于n达到1e12,所以我们分情况讨论。

1)a0形式,我们已经在特殊情况中指出,只有无穷个的时候才会符合条件

2)a0+a1*x形式,枚举a0,a1,我们判断(n-a0)是否能被a1整除,以及x是否大于max(a0,a1)即可。

3)a0+a1*x+a2*x^2,我们枚举a0,a1,a2,那么就相当于解一元二次方程。判断是否有整数解,是否整数解x>max(a0,a1,a2)即可。

4)不在上述三种形式内的,那么进制x最大也不会x^3>n,不然就会变成上述三种的形式。我们就可以枚举进制然后判断是否为幸运进制了。由于x^3<=n,所以复杂度只有1e4。

注意:就是上述的特殊情况,死的惨惨的。。

代码:

 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue> #define N 100005
#define M 10005
#define mod 1000000007
#define mod2 100000000
#define ll long long
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int T;
int f[N];
ll n; void ini()
{
memset(f,,sizeof(f));
int i,j;
int te,yu;
for(i=;i<=M;i++){
for(j=;j<=;j++){
te=i;
int flag=;
while(te){
yu=te%j;
if(yu!= && yu!= && yu!= && yu!=){
flag=;break;
}
te/=j;
}
if(flag==) f[i]++;
}
}
f[]=f[]=f[]=f[]=-; // for(i=1;i<=M;i++){
// printf(" i=%d f=%d\n",i,f[i]);
//}
} int main()
{
ll ans;
ll j,i,k;
ll a,b,c,d;
ll base;
//freopen("data.in","r",stdin);
// ini();
scanf("%d",&T);
for(int cnt=;cnt<=T;cnt++)
{
ans=;
printf("Case #%d: ",cnt);
scanf("%I64d",&n);
if(n>= && n<=){
printf("-1\n");continue;
} for(i=;i<=;i++){
for(j=;j<=;j++){
if( (n-i)%j== && (n-i)/j >max(i,j) ) ans++;
}
}
// printf(" %I64d\n",ans); for(i=;i<=;i++){
for(j=;j<=;j++){
for(k=;k<=;k++){
a=i;b=j;c=k-n;
ll te=sqrt(b*b-*a*c+0.5);
if(te*te!=b*b-*a*c) continue;
if(te<b) continue;
d=(te-b);
if(d%(*a)==){
base=d//a;
if(base>max(max(i,j),k))ans++;
}
}
}
} // printf(" %I64d\n",ans); //printf("%I64d\n",ans); for(j=;j*j*j<=n;j++){
ll te=n;
int flag=;
while(te){
ll yu=te%j;
if(yu!= && yu!= && yu!= && yu!=){
flag=;break;
}
te/=j;
}
if(flag==) ans++;
}
printf("%I64d\n",ans);
// } }
return ;
}

hdu 4937 2014 Multi-University Training Contest 7 1003的更多相关文章

  1. hdu 4915 Parenthese sequence--2014 Multi-University Training Contest 5

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4915 Parenthese sequence Time Limit: 2000/1000 MS (Ja ...

  2. hdu 4902 Nice boat--2014 Multi-University Training Contest 4

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=4902 Nice boat Time Limit: 30000/15000 MS (Java/Othe ...

  3. hdu 4925 Apple Tree--2014 Multi-University Training Contest 6

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others ...

  4. HDU校赛 | 2019 Multi-University Training Contest 6

    2019 Multi-University Training Contest 6 http://acm.hdu.edu.cn/contests/contest_show.php?cid=853 100 ...

  5. HDU校赛 | 2019 Multi-University Training Contest 5

    2019 Multi-University Training Contest 5 http://acm.hdu.edu.cn/contests/contest_show.php?cid=852 100 ...

  6. HDU校赛 | 2019 Multi-University Training Contest 4

    2019 Multi-University Training Contest 4 http://acm.hdu.edu.cn/contests/contest_show.php?cid=851 100 ...

  7. HDU校赛 | 2019 Multi-University Training Contest 3

    2019 Multi-University Training Contest 3 http://acm.hdu.edu.cn/contests/contest_show.php?cid=850 100 ...

  8. HDU校赛 | 2019 Multi-University Training Contest 2

    2019 Multi-University Training Contest 2 http://acm.hdu.edu.cn/contests/contest_show.php?cid=849 100 ...

  9. HDU校赛 | 2019 Multi-University Training Contest 1

    2019 Multi-University Training Contest 1 http://acm.hdu.edu.cn/contests/contest_show.php?cid=848 100 ...

随机推荐

  1. 【思维题 kmp 构造】bzoj4974: [Lydsy1708月赛]字符串大师

    字符串思博题这一块还是有点薄弱啊. Description 一个串T是S的循环节,当且仅当存在正整数k,使得S是T^k(即T重复k次)的前缀,比如abcd是abcdabcdab的循环节 .给定一个长度 ...

  2. MySQL数据库---索引

    索引的作用就是快速找出在一个列上用一特定值的行.如果没有索引,MySQL不得不首先以第一条记录开始并然后读完整个表直到它找出相关的行. 索引的类型: 先写一个建表语句: CREATE TABLE `t ...

  3. 14Shell脚本—判断语句

    判断语句 Shell脚本中的条件测试语法可以判断表达式是否成立,若条件成立则返回数字0,否则便返回其他随机数值. 条件测试语法的执行格式为 [ 条件表达式 ],切记,条件表达式两边均应有一个空格. 条 ...

  4. List删除元素

    在单线程环境下的解决办法 public void remove() { if (lastRet == -1) throw new IllegalStateException(); checkForCo ...

  5. German Collegiate Programming Contest 2015

    // Legacy Code #include <iostream> #include <cstdio> #include <cstring> #include & ...

  6. 算法导论 第七章 快速排序(python)

    用的最多的排序 平均性能:O(nlogn){随机化nlogn} 原地址排序 稳定性:不稳定 思想:分治 (切分左右) 学习方式:自己在纸上走一遍   def PARTITION(A,p,r): x = ...

  7. java处理excel

    JAVA EXCEL API:是一开放源码项目,通过它Java开发人员可以读取Excel文件的内容.创建新的Excel文件.更新已经存在的Excel文件.使用该API非Windows操作系统也可以通过 ...

  8. 百度地图的API接口----多地址查询和经纬度

    最近看了百度地图的API的接口,正想自己做点小东西,主要是多地址查询和经纬度坐标跟踪, 下面的代码直接另存为html就可以了,目前测试Chrome和360浏览器可以正常使用. <!DOCTYPE ...

  9. 如何打造一个"逼格"的web前端项目

    最近利用空余的时间(坐公交车看教程视频),重新了解了前后端分离,前端工程化等概念学习,思考如何打造一个“逼格”的web前端项目. 前端准备篇 前端代码规范:制定前端开发代码规范文档. PS:重中之中, ...

  10. 基于 FPGA 的图像边缘检测

    本文主要内容是实现图像的边缘检测功能 目录 mif文件的制作 调用 ip 核生成rom以及在 questasim 仿真注意问题 灰度处理 均值滤波:重点是3*3 像素阵列的生成 sobel边缘检测 图 ...