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\n",ans);
78     return 0;
79 } 
View Code

 

网络流

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

经典的最大流题POJ1273

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

 

转载于:https://www.cnblogs.com/DWVictor/p/10224965.html

Mersenne Twister The C extension underlying the random module includes code based on a download from http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html. The following are the verbatim comments from the original code:_random A C-program for MT19937, with initialization improved 2002/1/26. Coded by Takuji Nishimura and Makoto Matsumoto. Before using, initialize the state by using init_genrand(seed) or init_by_array(init_key, key_length). Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Any feedback is very welcome. 翻译下说的什么
最新发布
03-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值