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: 0 case #2: 1 for a single digit, 3, 4, 5, 6 is obviously-1 for two places, solving the equation A * x + B = N for three places, connect to Great Wall A * x ^ 2 + B * x + c = n. Other values start from 4 hexadecimal enumeration.#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>using namespace std;#define up(i,x,y) for(i=x;i<=y;i++)#define down(i,x,y) for(i=x;i>=y;i--)#define mem(a,b) memset(a,b,sizeof(a))#define w(x) while(x)#define ll __int64int main(){ int t,cas=1; ll n,tem,r,i,j,k,a,b,c,ans; scanf("%d",&t); w(t--) { ans=0; scanf("%I64d",&n); printf("Case #%d: ",cas++); if(n>2&&n<7) { printf("-1\n"); continue; } up(i,3,6) up(j,3,6) if((n-i)%j==0 && (n-i)/j>max(i,j)) ans++; up(i,3,6) up(j,3,6) up(k,3,6) { a=i,b=j,c=k-n; tem=(ll)sqrt(b*b-4*a*c+0.5); if(tem*tem!=b*b-4*a*c) continue; if((tem-b)%(2*a)) continue; tem=(tem-b)/(2*a); if(tem>max(i,max(j,k))) ans++; } for(i=4;i*i*i<=n;i++) { tem=n; w(tem) { r=tem%i; if(r<3||r>6) break; tem/=i; } if(!tem) ans++; } printf("%I64d\n",ans); } return 0;}