zoukankan      html  css  js  c++  java
  • D Makoto and a Blackboard

    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Makoto has a big blackboard with a positive integer nn written on it. He will perform the following action exactly kk times:

    Suppose the number currently written on the blackboard is vv. He will randomly pick one of the divisors of vv (possibly 11 and vv) and replace vv with this divisor. As Makoto uses his famous random number generator (RNG) and as he always uses 5858 as his generator seed, each divisor is guaranteed to be chosen with equal probability.

    He now wonders what is the expected value of the number written on the blackboard after kk steps.

    It can be shown that this value can be represented as PQPQ where PP and QQ are coprime integers and Q≢0(mod109+7)Q≢0(mod109+7). Print the value of PQ1P⋅Q−1 modulo 109+7109+7.

    Input

    The only line of the input contains two integers nn and kk (1n10151≤n≤1015, 1k1041≤k≤104).

    Output

    Print a single integer — the expected value of the number on the blackboard after kk steps as PQ1(mod109+7)P⋅Q−1(mod109+7) for PP, QQ defined above.

    Examples
    input
    6 1
    
    output
    3
    
    input
    6 2
    
    output
    875000008
    
    input
    60 5
    
    output
    237178099
    
    Note

    In the first example, after one step, the number written on the blackboard is 11, 22, 33 or 66 — each occurring with equal probability. Hence, the answer is 1+2+3+64=31+2+3+64=3.

    In the second example, the answer is equal to 1916+2316+3316+6116=1581⋅916+2⋅316+3⋅316+6⋅116=158.

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<algorithm>
     7 using namespace std;
     8 const int MAXN=40000000;
     9 const long long mod=1000000007;
    10 int k,pri[MAXN];
    11 bool exist[MAXN];
    12 long long n,inv[200],f[10050][200];
    13 long long pOw(long long a,long long m)
    14 {
    15     long long pro;
    16     for(pro=1LL;m;m>>=1,a=a*a%mod)
    17         if(m&1)
    18             pro=pro*a%mod;
    19     return pro;
    20 }
    21 void pre_calc()
    22 {
    23     memset(exist,true,sizeof(exist));
    24     pri[0]=0;
    25     for(int i=2;i<MAXN;i++)
    26     {
    27         if(exist[i]) pri[++pri[0]]=i;
    28         for(int j=1;j<=pri[0]&&(long long)i*pri[j]<MAXN;j++)
    29         {
    30             exist[i*pri[j]]=false;
    31             if(i%pri[j]==0)
    32                 break;
    33         }
    34     }
    35     inv[0]=1;
    36     for(int i=1;i<200;i++)
    37         inv[i]=pOw(i,mod-2);
    38     return;
    39 }
    40 long long calc(long long p,int num)
    41 {
    42     f[0][0]=1LL;
    43     for(int i=1;i<=num;i++)
    44         f[0][i]=f[0][i-1]*p%mod;
    45     for(int t=1;t<=k;t++)
    46     {
    47         f[t][0]=f[t-1][0];
    48         for(int i=1;i<=num;i++)
    49             f[t][i]=(f[t][i-1]+f[t-1][i])%mod;
    50         for(int i=1;i<=num;i++)
    51             f[t][i]=f[t][i]*inv[i+1]%mod;
    52     }
    53     return f[k][num];
    54 }
    55 int main()
    56 {
    57     int num;
    58     pre_calc();
    59     cin>>n>>k;
    60     long long ans=1LL;
    61     for(int i=1;i<=pri[0]&&(long long)pri[i]*pri[i]<=n;i++) if(n%pri[i]==0)
    62     {
    63         for(num=0;n%pri[i]==0;n/=pri[i],num++);
    64         ans=ans*calc(pri[i],num)%mod;
    65     }
    66     if(n!=1) ans=ans*calc(n,1)%mod;
    67     cout<<ans;
    68     fclose(stdin);
    69     fclose(stdout);
    70     return 0;
    71 }
    View Code

     

     

    学习一下
    
    Dinic+当前弧优化

    网络流的dinic算法详解以及当前弧优化备注:点开

     1 /*
     2     最大流 Dinic 
     3   
     4 */
     5 #include<iostream>
     6 #include<cstdio>
     7 #include<cstdlib>
     8 #include<string>
     9 #include<queue>
    10 #include<cstring>
    11 #define min(x,y)    ((x<y)?(x):(y))
    12 #define rev(i)(i&1?(i+1):(i-1))
    13 using namespace std;
    14 typedef long long ll;
    15 int dis[10005]; //分层图,距源点距离
    16 int cur[10005]; //当前弧优化 
    17 int n,m,ans,st,ed;
    18 struct node{
    19     int x,y,len,nxt;
    20     node(){}
    21     node(int nx,int ny,int nlen,int nnxt){
    22         x=nx;y=ny;len=nlen;nxt=nnxt;        
    23     }
    24 } E[200010];
    25 int head[10001],cnt;
    26 int bfs(){
    27     for (int i=1;i<=n;i++)  dis[i]=-1;
    28     queue<int> Q;
    29     dis[st]=0;Q.push(st);
    30     while (!Q.empty()){
    31         int j=Q.front();
    32         Q.pop();
    33         for (int i=head[j];i;i=E[i].nxt)
    34             if (dis[E[i].y]<0&&E[i].len>0){
    35                 dis[E[i].y]=dis[j]+1;
    36                 Q.push(E[i].y);
    37             }
    38     }
    39     if (dis[ed]>0)  return 1;
    40     else return 0;
    41 }
    42 int find(int x,int low){
    43     int res=0;
    44     if (x==ed)  return low;
    45     for (int i=cur[x];i;i=E[i].nxt){
    46     cur[x]=i;
    47     if (E[i].len>0&&dis[E[i].y]==dis[x]+1&&(res=find(E[i].y,min(low,E[i].len))))    
    48         {
    49             E[i].len-=res;
    50             E[i^1].len+=res;
    51             return res;
    52         }
    53     }
    54     return 0;
    55 }
    56 inline void link(int x,int y,int z){
    57     E[++cnt]=node(x,y,z,head[x]);
    58     head[x]=cnt;
    59     E[++cnt]=node(y,x,0,head[y]);
    60     head[y]=cnt;
    61 }
    62 int main(){
    63     scanf("%d%d%d%d",&n,&m,&st,&ed);
    64     cnt=1;  
    65     for (int i=1;i<=m;i++)
    66     {
    67         int a,b,c;
    68         scanf("%d%d%d",&a,&b,&c);
    69         link(a,b,c);
    70     }
    71     ans=0;int tans=0;
    72     while(bfs()){
    73         for (int i=1;i<=n;i++)  cur[i]=head[i];
    74         while (tans=find(st,2e6))   ans+=tans;
    75     }
    76 
    77     printf("%d
    ",ans);
    78     return 0;
    79 } 
    View Code

    网络流

    https://www.cnblogs.com/SYCstudio/p/7260613.html

    经典的最大流题POJ1273

    http://poj.org/problem?id=1273

  • 相关阅读:
    CentOS 7 firewalld vsftpd开放端口
    sqlalchemy操作----多表关联
    sqlalchemy 或者pysql 连接数据库时支持中文操作
    sqlalchemy操作----外键关联,relationship
    sqlalchemy操作----建表 插入 查询 删除
    python 操作mysql
    指针和二维数组的关系要点简单分析
    二维数组基本操作练习题
    单独取出整数的个位,十位,百位,以及素数的小综合题
    LeetCode | Add Two Numbers II
  • 原文地址:https://www.cnblogs.com/DWVictor/p/10224965.html
Copyright © 2011-2022 走看看