zoukankan      html  css  js  c++  java
  • 6069: Detachment(乘法逆元)

    6069: Detachment 分享至QQ空间

    时间限制(普通/Java):2000MS/6000MS     内存限制:65536KByte
    总提交: 33            测试通过:7

    描述

     

    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,a2, … (x= a1+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≠aj when i≠j).
    2.Make this multidimensional space size s as large as possible (s= a1∗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)

    输入

     

    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

    输出

     

    Maximum s you can get modulo 10^9+7. Note that we wants to be greatest product before modulo 10^9+7.

    样例输入

    样例输出

     4

     1 #include <bits/stdc++.h>
     2 #define ll long long
     3 using namespace std;
     4 
     5 int t,n;
     6 const int maxn=4e5+5;
     7 const int MOD=1e9+7;
     8 ll sum[maxn],inv[maxn],arr[maxn];
     9 
    10 inline int read(){
    11     int x=0,f=1;
    12     char ch=getchar();
    13     while(ch<'0'||ch>'9'){
    14         if(ch=='-') f=-1;
    15         ch=getchar();
    16     }
    17     while(ch>='0'&&ch<='9'){
    18         x=(x<<1)+(x<<3)+(ch^48);
    19         ch=getchar();
    20     }
    21     return x*f;
    22 }
    23 
    24 inline void write(ll x){
    25     if(x<0){
    26         putchar('-');
    27         x=-x;
    28     }
    29     if(x>9){
    30         write(x/10);
    31     }
    32     putchar(x%10+'0');
    33 }
    34 
    35 void cul(){
    36     sum[1]=0,inv[1]=1,arr[1]=1;
    37     for(int i=2;i<maxn;i++){
    38         sum[i]=sum[i-1]+i;
    39         arr[i]=arr[i-1]*i%MOD;
    40 //        inv[i]=(MOD-MOD/i*inv[MOD%i]%MOD)%MOD;   //线性求逆元
    41     }
    42 }
    43 
    44 ll Binary(ll ee){
    45     ll left=1,right=maxn-1;
    46     ll mid,ans;
    47     while(left<=right){
    48         mid=left+right>>1;
    49         if(sum[mid]<=ee){
    50             ans=mid;
    51             left=mid+1;
    52         }
    53         else right=mid-1;
    54     }
    55     return ans;   //返回下标
    56 }
    57 
    58 ll judge(ll a,ll m){
    59     ll ans=1;
    60     while(m){
    61         if(m&1) ans=(ans*a)%MOD;
    62         a=a*a%MOD;
    63         m>>=1;
    64     }
    65     return ans%MOD;
    66 }
    67 
    68 int main(){
    69     t=read();
    70     cul();
    71     while(t--){
    72         n=read();
    73         if(n<=4) {printf("%d
    ",n);continue;}
    74         ll ee=Binary(n);
    75         ll shu=n-sum[ee];
    76         ll res=-1;
    77         if(shu==ee){
    78             res=arr[ee]*judge(2,MOD-2)%MOD*(ee+2)%MOD;
    79         }
    80         else{
    81             res=arr[ee+1]*judge(arr[ee-shu+1],MOD-2)%MOD*arr[ee-shu]%MOD;
    82         }
    83         write(res);putchar('
    ');
    84     }
    85     return 0;
    86 }
    View Code
  • 相关阅读:
    《Mysql
    《算法
    《Redis
    《Mysql
    《Mysql
    SSH免密码登录
    TCP/IP四层模型和OSI七层模型的概念
    简单描述RAID级别:
    awk内置变量 awk有许多内置变量用来设置环境信息,这些变量可以被改变,下面给出了最常用的一些变量。
    awk 的逻辑运算字符
  • 原文地址:https://www.cnblogs.com/qq-1585047819/p/11838797.html
Copyright © 2011-2022 走看看