标签:des style http color os java io strong for
题目大意:给你一个十进制的数字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之间就行了。
2 10 19
Case #1: 0 Case #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.
#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; }
标签:des style http color os java io strong for
原文地址:http://blog.csdn.net/xu12110501127/article/details/38844717