本文主要是介绍hdu 4937 Lucky Number 科学暴力,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Lucky Number
“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.
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.
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.
思路:论科学的暴力的重要性。首先对于inf这种情况,一定是n=3,4,5,6,因为对于大于n的base,化为进制数还是由3,4,5,6组成的。
对于a1*x+a0这种形式的,枚举a1,a0,共16种情况。
对于a2*x^2+a1*x+a0这种形式,枚举a2,a1,a0,g共64种情况,解二次方程判断是否存在符合进制。
对于含有x三次方及其以上的,直接从4暴力枚举到1e4,看是否有可行的进制,详见代码:
// file name: 3.cpp //
// author: kereo //
// create time: 2014年08月12日 星期二 19时43分48秒 //
//***********************************//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN=10000+100;
#define L(x) (x<<1)
#define R(x) (x<<1|1)
ll n;
int main()
{int T,kase=0;scanf("%d",&T);while(T--){scanf("%I64d",&n);printf("Case #%d: ",++kase);if(n>=3 && n<=6){ printf("-1\n");continue;}ll 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,b=j,c=k-n;ll d=(ll)sqrt(b*b-4*a*c+0.5);if(d*d!=b*b-4*a*c)continue;if((d-b)%(2*a))continue;ll x=(d-b)/(2*a);if(x>max(i,max(j,k)))++ans;}for(ll i=4;i*i*i<=n;i++){ll x=n;while(x){if(x%i<3 || x%i >6)break;x/=i;}if(!x)ans++;}printf("%I64d\n",ans);}return 0;
}
这篇关于hdu 4937 Lucky Number 科学暴力的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!