hdu 4937 Lucky Number 2014 Multi-University Training Contest 7
来源:互联网 发布:aster遥感数据 编辑:程序博客网 时间:2024/05/22 05:08
Lucky Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 211 Accepted Submission(s): 55
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
Recommend
We have carefully selected several similar problems for you: 4944 4943 4942 4941 4940
比赛时怎么也没想到要特殊处理,就纠结于数据太大了
特殊处理只有1 2 3 位的情况 然后暴力枚举,数据量最大不会超过7000。
#include <cstdlib>#include <cstring>#include <cstdio>#include <iostream>#include <cmath>#include <algorithm>using namespace std;int ans;int main(){ int T; long long n; scanf("%d",&T); int cas=1; while(T--){ ans=0; scanf("%I64d",&n); if(n>=3&&n<=6){ printf("Case #%d: -1\n",cas++); continue; } for(int i=3;i<=6;i++) for(int j=3;j<=6;j++) if(n>i&&(n-i)%j==0&&(n-i)/j>i&&(n-i)/j>j)ans++; for(int i=3;i<=6;i++){ for(int j=3;j<=6;j++){ for(int k=3;k<=6;k++){ long long p=j*j-4*i*(k-n); if(p>0){ long long q=sqrt(p); if(q*q==p){ if((-j+q)%(2*i)==0) if((-j+q)/(2*i)>max(i,max(j,k)))ans++; } } } } } long long t,i; for(i=4;i*i*i<=n;i++){ t=n; while(t){ if(t%i<3||t%i>6)break; t/=i; } if(!t)ans++; } printf("Case #%d: %d\n",cas++,ans); } return 0;}
0 0
- hdu 4937 Lucky Number 2014 Multi-University Training Contest 7
- hdu 4952 Number Transformation--2014 Multi-University Training Contest 8
- hdu 4941 Magical Forest--2014 Multi-University Training Contest 7
- hdu 4941 Magical Forest 2014 Multi-University Training Contest 7
- hdu 4941 2014 Multi-University Training Contest 7 1007
- hdu 4941 Magical Forest 2014 Multi-University Training Contest 7
- HDU 6093 Rikka with Number (2017 Multi-University Training Contest
- 2014 Multi-University Training Contest 7小记
- 2014 Multi-University Training Contest 7 题解
- HDU 4952 Number Transformation(数学)——2014 Multi-University Training Contest 8
- Hdu4952 - Number Transformation - 数论(2014 Multi-University Training Contest 8)
- hdu 4861 Couple doubi ---2014 Multi-University Training Contest 1
- hdu 4864 Task---2014 Multi-University Training Contest 1
- 2014 Multi-University Training Contest 1 - 1004 / hdu 4864 Task
- hdu 4902 Nice boat--2014 Multi-University Training Contest 4
- [HDU 4862][2014 Multi-University Training Contest 1]Jump
- hdu 4915 Parenthese sequence--2014 Multi-University Training Contest 5
- hdu 4911 Inversion--2014 Multi-University Training Contest 5
- android后台录像 --未验证
- HDU 4941 Magical Forest 【离散化】【map】
- hdu2013 三角形 20140812.cpp
- 前端开发中的CSS的长度单位em、px、ex、%
- android 后台视频录制【原创】
- hdu 4937 Lucky Number 2014 Multi-University Training Contest 7
- OC内存管理之release
- 第一篇博客!!!
- android硬编码h264-MediaCodec
- 4.3.7 Kill the monster
- oracle spfile 和 pfile
- 阻塞IO服务器模型之单线程服务器模型
- This is it——要学老队长,强行秀英语
- mysql oracle informix SqlServer 分页语句