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. cocos2dx 通过jni调用安卓底层方法

    cocos2dx通过封装JniHelper类来调用安卓api底层函数,该文件在cocos/platform/android/jni/JniHelper.h,使用方法如下: 打开eclipse,导入co ...

  2. 【线段树 树链剖分 差分 经典技巧】loj#3046. 「ZJOI2019」语言【未完】

    还是来致敬一下那过往吧 题目分析 先丢代码 #include<bits/stdc++.h> ; ; ; struct node { int top,son,fa,tot; }a[maxn] ...

  3. spring boot自动配置实现

    自从用了spring boot,都忘记spring mvc中的xml配置是个什么东西了,再也回不去.为啥spring boot这么好用呢, 约定大于配置的设计初衷, 让我们只知道维护好applicat ...

  4. windows 2008r2+php5.6.28环境搭建详细过程

    安装IIS7 安装php 网站验证 安装IIS7 1.打开服务器管理器(开始-计算机-右键-管理-也可以打开),添加角色 直接下一步 勾选Web服务器(IIS),下一步,有个注意事项继续下一步(这里我 ...

  5. sqli-labs less1 &&less3&&less4学习心得

    0x01.less1 id=1/ id=1 and 1=1结果正常 id=1 and 1=2结果正常,不合理 id=1'提示:

  6. phpMyAdmin关于PHP 5.5+ is required. Currently installed version is: 5.4.16问题

    出现这个提示PHP 5.5+ is required. Currently installed version is: 5.4.16原因可能是: phpmyadmin 版本太新,最小需要php5.5. ...

  7. POJ 1791 Parallelogram Counting(求平行四边形数量)

    Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...

  8. 打造一款属于自己的web服务器——从简单开始

    距离开篇已经过了很久,期间完善了一下之前的版本,目前已经能够完好运行,基本上该有的功能都有了,此外将原来的测试程序改为示例项目,新项目只需按照示例项目结构实现controller和view即可,详情见 ...

  9. 网络编程-TCP/IP各层介绍(5层模型讲解)

    1.TCP/IP五层协议讲解 物理层--数据链路层--网络层--传输层--应用层 我们将应用层,表示层,会话层并作应用层,从tcp/ip五层协议的角度来阐述每层的由来与功能,搞清楚了每层的主要协议 就 ...

  10. webdriver高级应用- 操作富文本框

    富文本框的技术实现和普通的文本框的定位存在较大的区别,富文本框的常见技术用到了Frame标签,并且在Frame里面实现了一个完整的HTML网页结构,所以使用普通的定位模式将无法直接定位到富文本框对象. ...