HDU Problem - 5976 Detachment(逆元,阶乘打表,数学)
題目鏈接
Problem Description
In a highly developed alien society, the habitats are almost infinite dimensional space.In the history of this planet,there is an old puzzle.You have a line segment with x units’ length representing one dimension.The line segment can be split into a number of small line segments: a1,a2a1,a2, … (x= a1+a2a1+a2+…) assigned to different dimensions. And then, the multidimensional space has been established. Now there are two requirements for this space: 1.Two different small line segments cannot be equal ( ai≠ajai≠aj when i≠j).2.Make this multidimensional space size s as large as possible (s= a1?a2a1?a2*…).Note that it allows to keep one dimension.That’s to say, the number of ai can be only one.Now can you solve this question and find the maximum size of the space?(For the final number is too large,your answer will be modulo 10^9+7)
Input
The first line is an integer T,meaning the number of test cases.Then T lines follow. Each line contains one integer x.1≤T≤10^6, 1≤x≤10^9
Output
Maximum s you can get modulo 10^9+7. Note that we wants to be greatest product before modulo 10^9+7.
Sample Input
1 4Sample Output
4AC
- 一個數(shù)字分成多個不相同的數(shù)字相乘,首先分成1不合理,因為1乘以一個數(shù)結(jié)果不增加,從2枚舉所有X可以分出的連續(xù)數(shù)字,最后可能會剩余幾個數(shù)字,可以把剩余的數(shù)字看成N個1,剩下任務就是將這N個1分出去,從最后一個數(shù)字開始往前每個數(shù)字加1,這樣能保證連續(xù)的情況下乘積最大,這樣就有兩種情況,剩下的數(shù)字能分完和不能分完(多了個1),例如8 = 2 +3 +3,最后一個3分給前面兩個數(shù)字之后多了個1,這個1就分到最后一個數(shù)字上,例如8 = 2 +3 +2,這樣剛好分完
- 數(shù)據(jù)規(guī)模大,一共有1e6的詢問,時間要求在2秒,所以每次最好O(1)算出結(jié)果,觀察上面的思路,最后的得到的數(shù)字,就是部分連續(xù)的數(shù)字相乘,可以用階乘打表處理,另外存在相除的情況,所以也要逆元打表,判斷最后一個數(shù)字是否能分完,需要用到sum前綴
總結(jié)
以上是生活随笔為你收集整理的HDU Problem - 5976 Detachment(逆元,阶乘打表,数学)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HDU Problem - 5971 W
- 下一篇: 牛客练习赛25 B-最长区间