日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

hdu 4937 Lucky Number(数学题 进制转换)2014多校训练第7场

發(fā)布時(shí)間:2025/3/16 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdu 4937 Lucky Number(数学题 进制转换)2014多校训练第7场 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Lucky Number

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 131072/131072 K (Java/Others)

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.
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.
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: 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. 題意:Love_Kid將3,4,5,6認(rèn)為是幸運(yùn)數(shù)字。給定一個(gè)十進(jìn)制數(shù)n。現(xiàn)在可以講起任意轉(zhuǎn)換成其他進(jìn)制,但轉(zhuǎn)換后的數(shù)必須是由3,4,5,6構(gòu)成的,而這個(gè)進(jìn)制稱(chēng)為幸運(yùn)進(jìn)制。問(wèn)有多少個(gè)幸運(yùn)進(jìn)制。若有無(wú)數(shù)個(gè),則輸出-1。例如19在5進(jìn)制下是34,所以5是幸運(yùn)進(jìn)制。 分析:對(duì)于只有一位數(shù)的情況,顯然3、4、5、6都應(yīng)該輸出-1. ? 如果有2位數(shù),假設(shè)這2位中高位為a,低位為b,進(jìn)制為base,則 n = a * base + b,解一元一次方程即可。 ??如果有3位數(shù),假設(shè)這3為從高到低分別為a、b、c,進(jìn)制為base,則 n = a * base * base + b * base + c,即一元二次方程即可。 ??如果位數(shù)>= 4,可以暴力枚舉進(jìn)制數(shù)。base>min(3,4,5,6),所以從base=4開(kāi)始枚舉。又因?yàn)?x1 + x2 * base + x3 * base * base + x4 * base *base *base + ……>= 3*7000+3 *7000 ^2 +3 * 7000 ^3 = 1.029e12 > max(n). 所以枚舉4到7000就可以了。 #include<cstdio> #include<cmath> #include<algorithm> using namespace std; typedef __int64 LL; LL Max(LL a, LL b, LL c) {return max(a, max(b, c)); } int main() {int T, cas = 0;LL n, i, j, k, a, b, c, delta, x, t;scanf("%d",&T);while(T--) {LL ans = 0;scanf("%I64d",&n);printf("Case #%d: ", ++cas);if(n >= 3 && n <= 6) {printf("-1\n");continue;}// n = j * x + i, x > max(i, j), 轉(zhuǎn)化后只有2位數(shù)for(i = 3; i <= 6; i++) {for(j = 3; j <= 6; j++) {if((n - i) % j == 0 && (n - i) / j > max(i, j))ans++;}}// n = i * x * x + j * x + k, 轉(zhuǎn)化后只有3位數(shù)for(i = 3; i <= 6; i++) {for(j = 3; j <= 6; j++) {for(k = 3; k <= 6; k++) {a = i; b = j; c = k - n;delta = (LL)sqrt(b * b - 4 * a * c + 0.5);if(delta * delta != (b * b - 4 * a * c)) continue;if((delta - b) % (2 * a)) continue; //負(fù)根直接舍棄x = (delta - b) / (2 * a); if(x > Max(i, j, k))ans++;}}}//其他情況for(i = 4; i * i * i <= n; i++) {t = n;while(t) {if(t % i < 3 || t % i > 6)break;t = t / i;}if(!t) ans++;}printf("%I64d\n", ans);}return 0; }


總結(jié)

以上是生活随笔為你收集整理的hdu 4937 Lucky Number(数学题 进制转换)2014多校训练第7场的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。