hdu 4937 2014 Multi-University Training Contest 7 1003
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 ...
随机推荐
- 学习笔记(五): Feature Crosses
目录 Feature Crosses Encoding Nonlinearity Kinds of feature crosses Glossay Crossing One-Hot Vectors P ...
- 了解swagger
https://blog.csdn.net/i6448038/article/details/77622977 随着互联网技术的发展,现在的网站架构基本都由原来的后端渲染,变成了:前端渲染.先后端分离 ...
- Tcl/Cmds
- 「新手必看」Python+Opencv实现摄像头调用RGB图像并转换成HSV模型
在ROS机器人的应用开发中,调用摄像头进行机器视觉处理是比较常见的方法,现在把利用opencv和python语言实现摄像头调用并转换成HSV模型的方法分享出来,希望能对学习ROS机器人的新手们一点帮助 ...
- LeetCode(168) Excel Sheet Column Title
题目 Given a positive integer, return its corresponding column title as appear in an Excel sheet. For ...
- holtek编程注意事项
1.holtek单片机中断服务函数中函数调用里的参数不能传递地址,不然程序就会跑飞 2.holtek单片机尽量不要函数嵌套很多层,嵌套过多,会导致单片机复位
- #1 add life to static pages && connect to MySQL
由于实验室 Project 中需要用到PHP, 之前也没接触过 PHP, 因此把 编程入门 <Head Fist PHP & MySQL >找来花了四五天快速过了一遍. 现在想把书 ...
- 百度地图的API接口----多地址查询和经纬度
最近看了百度地图的API的接口,正想自己做点小东西,主要是多地址查询和经纬度坐标跟踪, 下面的代码直接另存为html就可以了,目前测试Chrome和360浏览器可以正常使用. <!DOCTYPE ...
- [python][oldboy]关键字参数和位置参数,默认参数,可变长参数(无名,有名)
关键字参数和位置参数是在函数调用的时候定义 关键字参数是以键-值对出现,无序,多一个不行,少一个不行 位置参数,有序,多一个不行,少一个不行 混搭:所有位置参数必须在关键字参数的左边 默认参数是在函数 ...
- 以前刷过的数位dp
TOJ1688: Round Numbers Description The cows, as you know, have no fingers or thumbs and thus are una ...