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. 20181111 计时器影响DOM点击事件的逻辑

    今天在群里看见一个人在问"点击按钮使图片产生旋转为什么要使用计时器来实现",我自己操作了一遍她的代码才发现里面的逻辑实现很有意思,所以写出来分享一下. 她的代码是这样写的: < ...

  2. nginx日志相关优化安全

    一.编写脚本实现nginx access日志轮询 配置日志切割脚本,如下: [root@nginx shell]# cat cut_nginx_log.sh #!/bin/bash #Author:M ...

  3. 李涛ps高手之路

    下载地址:http://www.ly89.cn/detailR/21.html

  4. oop中 限制文件类型和大小

    <?php /** * Created by IntelliJ IDEA. * User: jiabinwang * Date: 7/5/18 * Time: 8:46 PM */ namesp ...

  5. 我的Python分析成长之路7

    类 一.编程范式: 1.函数式编程   def 2.面向过程编程   (Procedural Programming) 基本设计思路就是程序一开始是要着手解决一个大的问题,然后把一个大问题分解成很多个 ...

  6. 【HIHOCODER 1055】 刷油漆(树上背包)

    描述 小Ho有着一棵灰常好玩的树玩具!这棵树玩具是由N个小球和N-1根木棍拼凑而成,这N个小球都被小Ho标上了不同的数字,并且这些数字都是处于1..N的范围之内,每根木棍都连接着两个不同的小球,并且保 ...

  7. Numpy+Pandas读取数据

    1.为什么使用Numpy+Pandas 在使用Numpy读取csv文件时,文件中含有字符串时,会出现ValueError错误 2.Pandas读取csv文件:

  8. HDU 1827 强连通 缩点 Summer Holiday

    求出强连通分量,因为强连通中只要有一个人被通知到了,所有人都能被通知到. 缩点以后形成一个DAG,找出那些入度为0的点,累加上它们的权值就是答案.一个点的权值等于SCC中权值最小的那个点. #incl ...

  9. Python之code对象与pyc文件(三)

    上一节:Python之code对象与pyc文件(二) 向pyc写入字符串 在了解Python如何将字符串写入到pyc文件的机制之前,我们先来了解一下结构体WFILE: marshal.c typede ...

  10. python redis中blpop和lpop的区别

    python redis 中blpop返回的是元组对象,因此返回的时候注意 lpop返回的是对象