HDU 4937 Lucky Number(列舉進位制)
題目大意:給你一個十進位制的數字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.
“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.
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
#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 4135——Co-prime(容斥原理&&二進位制列舉)
- 2013南京站I題||hdu4810 二進位制列舉
- 二進位制陣列陣列
- HDU 6034 Balala Power!(大數進位制)
- oracle進位制轉換to_number_to_char_bin_to_numOracle
- 在C#中對列舉進行位運算--列舉組合C#
- 進位制詳解:二進位制、八進位制和十六進位制
- 二進位制陣列 subarray() 方法陣列
- 【進位制轉換】二進位制、十六進位制、十進位制、八進位制對應關係
- NUMBER BASE CONVERSION(進位制轉換) 經典模擬
- 計算機基礎進位制轉換(二進位制、八進位制、十進位制、十六進位制)計算機
- 二進位制,八進位制,十進位制,十六進位制的相互轉換
- JavaScript 二進位制、八進位制與十六進位制JavaScript
- JavaScript 進位制轉換(2進位制、8進位制、10進位制、16進位制之間的轉換)JavaScript
- java中二進位制、八進位制、十進位制、十六進位制的轉換Java
- 二進位制,八進位制,十進位制,十六進位制之間的轉換
- Python 進位制互相轉換(二進位制、十進位制和十六進位制)Python
- JAVA 二進位制,八進位制,十六進位制,十進位制間進行相互轉換Java
- Qt進位制轉換(十進位制轉十六進位制)QT
- 二進位制陣列 buffer 屬性陣列
- 二進位制陣列 length 屬性陣列
- 1474 十進位制轉m進位制+1475 m進位制轉十進位制
- [計算機基礎] 計算機進位制轉換:二進位制、八進位制、十進位制、十六進位制計算機
- C# 2進位制、8進位制、10進位制、16進位制...各種進位制間的輕鬆轉換C#
- n進位制轉十進位制
- 十進位制轉十六進位制
- 10進位制 VS 2進位制
- 二進位制、十進位制與十六進位制相互轉化
- 大話二進位制,八進位制,十進位制,十六進位制之間的轉換
- 一看就懂二進位制、八進位制、十六進位制數轉換十進位制
- python進位制轉換(二進位制、十進位制和十六進位制)及注意事項Python
- Oracle中的二進位制、八進位制、十進位制、十六進位制相互轉換函式Oracle函式
- 進位制之間的轉換之“十六進位制 轉 十進位制 轉 二進位制 方案”
- 十進位制——二 (八、十六 )進位制
- 45:十進位制到八進位制
- 46:八進位制到十進位制
- 十六進位制數轉十進位制
- JavaScript二進位制陣列建立注意點JavaScript陣列