HDOJ 4937 Lucky Number
来源:互联网 发布:网络公关公司良心哥 编辑:程序博客网 时间:2024/06/04 17:49
当进制转换后所剩下的为数较少时(2位,3位),对应的base都比较大,可以用数学的方法计算出来。
预处理掉转换后位数为3位后,base就小于n的3次方了,可以暴力计算。。。。
Lucky Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 521 Accepted Submission(s): 150
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.
“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.
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
21019
Sample Output
Case #1: 0Case #2: 1Hint10 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
2014 Multi-University Training Contest 7
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <set>#include <cmath>using namespace std;typedef long long int LL;LL n;set<LL> ans;bool change(LL x,LL base){ bool flag=true; while(x) { LL temp=x%base; x/=base; if(temp>=3LL&&temp<=6LL) continue; else { flag=false; break; } } return flag;}int main(){ int T_T,cas=1; scanf("%d",&T_T); while(T_T--) { ans.clear(); cin>>n; if(n>=3LL&&n<=6LL) { cout<<"Case #"<<cas++<<": -1"<<endl; continue; } for(LL a=3;a<=6;a++) { for(LL b=3;b<=6;b++) { LL limit=max(a,b); if( (n-b)%a == 0 ) { if( (n-b)/a > limit) { ans.insert((n-b)/a); } } } } for(LL a=3;a<=6;a++) { for(LL b=3;b<=6;b++) { for(LL c=3;c<=6;c++) { LL C=c-n; if(b*b >= 4LL*a*C ) { LL deta=sqrt(b*b-4LL*a*C); LL base1=(-b+deta)/(2*a); LL base2=(-b-deta)/(2*a); LL limit=max(a,max(b,c)); if(a*base1*base1+b*base1+c==n && base1>limit) { ans.insert(base1); } if(a*base2*base2+b*base2+c==n && base2>limit) { ans.insert(base2); } } } } } for(LL i=4;i*i*i<=n;i++) { if(change(n,i)) { ans.insert(i); } } cout<<"Case #"<<cas++<<": "<<ans.size()<<endl; } return 0;}
1 0
- HDOJ 4937 Lucky Number
- HDOJ 4937 Lucky Number
- hdoj 4937 Lucky Number【想法】
- hdoj 4937 Lucky Number 【思维题】
- HDU 4937 Lucky Number
- HDU 4937 Lucky Number
- hdu 4937 Lucky Number
- HDU-4937-Lucky Number
- HDU - 4937 Lucky Number
- hdu 4937 Lucky Number
- HDU 4937 Lucky Number
- HDU 4937 Lucky Number
- HDU 4937Lucky Number
- hdu 4937 Lucky Number(数论)
- hdu 4937 Lucky Number 数学
- HDU 4937 Lucky Number(数论)
- HDU 4937 Lucky Number 【搜索】
- lucky number
- 前端开发神器 Emmet 介绍
- Struts2中访问web元素的四种方式及前台jsp页面获取后台值的方式
- WUBI安裝ubuntu 14.04过程及配置笔记
- 设计模式之代理模式
- 此次行程V型成V型成V型从
- HDOJ 4937 Lucky Number
- Graphviz
- 变成成CVCV刹相册v
- Corn Fields
- 安卓对话框之----下拉列表框(Spinner)
- uva 216(暴力求解)
- android sdk下载不了,解决方案
- fdgdgdfgdfgdfhdhgf
- Java死锁举例