hdu 5976 Detachment

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 ( aiajai≠aj when i≠j). 
2.Make this multidimensional space size s as large as possible (s= a1a2a1∗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. 
Then T lines follow. Each line contains one integer x. 
1≤T≤10^6, 1≤x≤10^9OutputMaximum s you can get modulo 10^9+7. Note that we wants to be greatest product before modulo 10^9+7.Sample Input

1
4

Sample Output

4
解题思路:
存在一个数可以将它分成任意数量数相加而得,求分解成的数的最大成绩,如何使其乘积最大?假设有一个数字n分为两个那么要使乘积最大就是n/2*n/2,分成三份就是n/3*n/3
*n/3,类推可得最大的肯定为2*2*2....,但题目要求数字不能相同那么只能分解为2+3+4+5...,但并不是每一个数都能分解成这样,不如当n=6,2+3=5,n多出了一,那么我们把这个1
加入到3上去那么就是2*4=8,最大积。当n不为等差数列和的时候我们只要把最接近n的数列和和n的差值,将差值转换为从后往前每个加一,其实也就是将数列的其中一部分统统后移一个位置
当n=23原先是2+3+4+5+6变成2+3+5+6+7,唯一的变化就是中间少了一个4,后面=多了一个7,因为这道题是多组输入需要预处理,所以只能先求前缀和和前缀积,然后找到需要减去的位置
用乘法逆元除去那个值,最后乘上下一位。最坑的是这里有一个特殊判断,因为数列是从2开始计算,当差值正好和最后一位相同时,如n=19,ans=19-(2+3+4+5)=5,但前面只有4个数,从
后往前加:3+4+5+6此时多了1,再把它从后往前加3+4+5+7.想到这些就很容易了
ps:这个题有毒,同一份代码第一次交tle,再交一次就ac了
实现代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int inf = 1000000007;
void exgcd(ll a,ll b,ll& d,ll& x,ll& y)
{
    if(!b){d=a;x=1;y=0;}
    else
    {
        exgcd(b,a%b,d,y,x);
        y-=x*(a/b);
    }
}

ll inv(ll a,ll n)
{
    ll d, x, y;
    exgcd(a,n,d,x,y);
    return (x+n)%n;
}
ll h[50000],j[50000];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll num1 = 0,num2=1,cnt=1,i,t,n,sum,ans;
    h[0] = 1;j[0]=1;
    for(i=2;i<50000;i++){
        num1+=i;
        //cout<<num1<<endl;
        if(num1>inf)
            break;
        h[cnt++]=num1;
        num2=(num2*i)%inf;
        j[cnt-1]=num2;
    }
    cin>>t;
    while(t--){
        cin>>n;
        if(n==1){
            cout<<"1"<<endl;
            continue;
        }
        int k = lower_bound(h+1,h+cnt,n) - h;
        //cout<<"k: "<<k<<endl;
        if(h[k]==n){
            cout<<j[k]<<endl;
            continue;
        }
        else{
            ans = n-h[k-1];
            //cout<<"h[k-1] :"<<h[k-1]<<endl;
            //cout<<"j[k-1] :"<<j[k-1]<<endl;
            //cout<<"ans :"<<ans<<endl;
            //cout<<"k "<<k+2<<endl;
            if(ans==k)
            sum=((j[k-1]*inv(2,inf)%inf)*(k+2))%inf;
            else
            sum = ((j[k-1]*inv(k-ans+1,inf)%inf)*(k+1))%inf;
            cout<<sum<<endl;
        }
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/kls123/p/7249452.html

乐播投屏是一款简单好用、功能强大的专业投屏软件,支持手机投屏电视、手机投电脑、电脑投电视等多种投屏方式。 多端兼容与跨网投屏:支持手机、平板、电脑等多种设备之间的自由组合投屏,且无需连接 WiFi,通过跨屏技术打破网络限制,扫一扫即可投屏。 广泛的应用支持:支持 10000+APP 投屏,包括综合视频、网盘与浏览器、美韩剧、斗鱼、虎牙等直播平台,还能将央视、湖南卫视等各大卫视的直播内容一键投屏。 高清流畅投屏体验:腾讯独家智能音画调校技术,支持 4K 高清画质、240Hz 超高帧率,低延迟不卡顿,能为用户提供更高清、流畅的视觉享受。 会议办公功能强大:拥有全球唯一的 “超级投屏空间”,扫码即投,无需安装。支持多人共享投屏、远程协作批注,PPT、Excel、视频等文件都能流畅展示,还具备企业级安全加密,保障会议资料不泄露。 多人互动功能:支持多人投屏,邀请好友加入投屏互动,远程也可加入。同时具备一屏多显、语音互动功能,支持多人连麦,实时语音交流。 文件支持全面:支持 PPT、PDF、Word、Excel 等办公文件,以及视频、图片等多种类型文件的投屏,还支持网盘直投,无需下载和转格式。 特色功能丰富:投屏时可同步录制投屏画面,部分版本还支持通过触控屏或电视端外接鼠标反控电脑,以及在投屏过程中用画笔实时标注等功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值