Lucky Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 664 Accepted Submission(s): 194
“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.
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.
10
19
Case #2: 1
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.
题意:
我们将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的更多相关文章
-
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 ...
-
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 ...
-
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 ...
-
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 ...
-
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 ...
-
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 ...
-
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 ...
-
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 ...
-
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 ...
随机推荐
-
【Python五篇慢慢弹(3)】函数修行知python
函数修行知python 作者:白宁超 2016年10月9日21:51:52 摘要:继<快速上手学python>一文之后,笔者又将python官方文档认真学习下.官方给出的pythondoc ...
-
BGP路由协议详解(完整篇)
原文链接:http://xuanbo.blog.51cto.com/499334/465596/ 2010-12-27 12:02:45 上个月我写一篇关于BGP协议的博文,曾许诺过要完善这个文档,但 ...
-
BZOJ3424 : Poi2013 Multidrink
详细做法以及证明请看论文<Hamiltonian paths in the square of a tree>. 首先将1到n的路径提取出来,作为主干. 定义毛毛虫为去掉叶子之后只有一条单 ...
-
圆内,求离圆心最远的整数点 hiho一下第111周 Farthest Point
// 圆内,求离圆心最远的整数点 hiho一下第111周 Farthest Point // 思路:直接暴力绝对T // 先确定x范围,每个x范围内,离圆心最远的点一定是y轴两端的点.枚举x的范围,再 ...
-
Android 开发之网易云音乐(或QQ音乐)的播放界面转盘和自定义SeekBar的实现
这个东西我在eoeAndroid上首发的,但没有详细的实现说明:http://www.eoeandroid.com/thread-317901-1-1.html 在csdn上进行详细的说明吧.(同时上 ...
-
解决Ubuntu中phpmyadmin对数据上传上限2M
本文部分参考自:http://www.myhack58.com/Article/sort099/sort0102/2011/29396.htm 原文有少量错误或者过时的(相对于ubuntu15来说)内 ...
-
学会C sharp计算机编程语言 轻松开发财务、统计软件
就像人们用同一种语言才可以顺畅交流一样,语言是计算机编程的根本,是IT世界交流的工具.运用这些计算机语言,人们可以创造出一个美妙的世界.你点击某个网页或是安装一个应用程序软件,这简简单单动作的背后,就 ...
-
hdu2544 最短路 Dijkstra算法
最短路(Dijkstra算法模板题) Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
-
GCD(IV)
死锁:2个任务相互等待造成的. - (void) GCD { NSLog(@"begin"); dispatch_queue_t queue = dispatch_queue_cr ...
-
ubuntu 挂载虚拟机vdi文件
sudo apt-get install nbd-server nbd-client qemu-kvm # rmmod nbd # modprobe nbd max_part=8 # qemu- ...