Give you a decimal number N, and then ask if you want to convert each digit into a certain number which may be 3, 4, 5, 6. determine the number of qualified hexadecimal formats.
Solution: although this question does not mean how big the system is, we can simply analyze it. The upper limit of N is 10 ^ 12. If there are four digits, the number must be at least three to the power, so the maximum value of the hexadecimal structure is 10000.
So let's enumerate, when a digit is 3, 4, 5, and 6, it is obviously-1.
Solve a * x + B = N in two cases.
Triplicate: A * x ^ 2 + B * x + c = n.
When there are four digits, you can check whether the result after the remainder of each digit falls between 3 and 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.
Inputthere 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.
Outputfor 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.
Authoruestc
Source2014 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;}
HDU 4937 lucky number (enumeration hexadecimal)