HDU 5976 贪心+逆元
程序员文章站
2023-12-22 15:58:16
...
F - Detachment
HDU - 5976In 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)
InputThe first line is an integer T,meaning the number of test cases. 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)
Then T lines follow. Each line contains one integer x.
1≤T≤10^6, 1≤x≤10^9 OutputMaximum 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
4
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long LL;
#define MOD 1000000007
#define maxn 50000
LL a[maxn];
LL sum[maxn];
LL mul[maxn];
void init()
{
a[0]=sum[0]=a[1]=sum[1]=0;
a[2]=2;sum[2]=2;
for(int i=3;i<maxn;i++)
{
a[i]=i;
sum[i]=a[i]+sum[i-1];
}
mul[0]=0;mul[1]=1;
for(int i=2;i<maxn;i++)
mul[i]=(mul[i-1]*i)%MOD;
}
LL quickpow(LL m,LL n)
{
LL b=1;
while(n>0)
{
if(n&1)b=(b*m)%MOD;
n=n>>1;
m=(m*m)%MOD;
}return b;
}
int main()
{
int t,n;
scanf("%d",&t);
init();
//for(int i=0;i<13;i++)
//cout<<mul[i]<<endl;
while(t--)
{
scanf("%d",&n);
if(n<=4){cout<<n<<endl;continue;}
int biao=upper_bound(sum,sum+maxn,n)-sum;
int remain=n-sum[biao-1];
LL ans=0;
if(remain==biao-1)
ans=((mul[biao+1]*quickpow(2,MOD-2))%MOD*quickpow(biao,MOD-2))%MOD;
else
{
int temp=biao-remain;
ans=(mul[biao]*quickpow(temp,MOD-2))%MOD;
}
printf("%lld\n",ans);
}
return 0;
}
推荐阅读
-
HDU 5976 贪心+逆元
-
HDU 1052(田忌赛马 贪心)
-
hdu-1338 game predictions(贪心题)
-
Too Rich HDU - 5527 (贪心+dfs)
-
HDU6299 Balanced Sequence (多校第一场1002) (贪心)
-
[HDU多校2020]第三场 1004 Tokitsukaze and Multiple (贪心/dp)
-
HDU5698 瞬间移动(求逆元)
-
HDU 4310 Hero【贪心】
-
HDU6301 Distinct Values (多校第一场1004) (贪心)
-
Duizi and Shunzi HDU - 6188 (贪心)2017 广西ACM/ICPC