题目大意:给你一个十进制的数字n,然后问你转化为某一进制后它的每一位的数字只可能为3,4,5,6.求这种符合条件的进制有多少种。
解题思路:这题虽然没说进制有多大但是我们可以简单的分析一下,n的上限是10^12,如果有四位数字的话,那至少要出现三次方,所以进制最大为10000。
所以我们枚举一下,一位的时候3,4,5,6显然为-1.
两位的时候解一下a*x+b = n。
三位时解一下:a*x^2+b*x+c = n。
四位的时候看每一位取余后的结果是否落在3-6之间就行了。
Lucky Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1201 Accepted Submission(s): 358
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
2014 Multi-University Training Contest 7
#include <algorithm> #include <iostream> #include <stdlib.h> #include <string.h> #include <iomanip> #include <stdio.h> #include <string> #include <queue> #include <cmath> #include <stack> #include <map> #include <set> #define eps 1e-10 ///#define M 1000100 ///#define LL __int64 #define LL long long ///#define INF 0x7ffffff #define INF 0x3f3f3f3f #define PI 3.1415926535898 #define zero(x) ((fabs(x)<eps)?0:x) using namespace std; const int maxn = 510; int main() { int T; cin >>T; int Case = 1; while(T--) { LL n; scanf("%I64d",&n); cout<<"Case #"<<Case++<<": "; if(n == 3LL || n == 4LL || n == 5LL || n == 6LL) { cout<<-1<<endl; continue; } int ans = 0; for(LL i = 3; i <= 6; i++) for(LL j = 3; j <= 6; j++) if((n-i)%j == 0 && (n-i)/j > max(i, j)) ans++; for(LL i = 3; i <= 6; i++) { for(LL j = 3; j <= 6; j++) { for(LL k = 3; k <= 6; k++) { LL a = i; LL b = j; LL c = k-n; LL tmp = sqrt(b*b-4*a*c); if(tmp*tmp != b*b-4*a*c) continue; if((tmp-b)%(2*a)) continue; if((tmp-b)/(2*a) > max(a, max(b, c))) ans++; } } } for(LL i = 4; i*i*i <= n; i++) { LL tmp = n; while(tmp) { int x = tmp%i; if(x < 3 || x > 6) break; tmp /= i; } if(!tmp) ans++; } cout<<ans<<endl; } return 0; }