Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- */
- //#pragma comment(linker, "/STACK:16777216")
- #include <fstream>
- #include <iostream>
- #include <string>
- #include <complex>
- #include <math.h>
- #include <set>
- #include <vector>
- #include <map>
- #include <queue>
- #include <stdio.h>
- #include <stack>
- #include <algorithm>
- #include <list>
- #include <ctime>
- #include <memory.h>
- #include <ctime>
- #define y0 sdkfaslhagaklsldk
- #define y1 aasdfasdfasdf
- #define yn askfhwqriuperikldjk
- #define j1 assdgsdgasghsf
- #define tm sdfjahlfasfh
- #define lr asgasgash
- #define eps 1e-9
- //#define M_PI 3.141592653589793
- #define bs 1000000007
- #define bsize 256
- #define right adsgasgadsg
- #define free adsgasdg
- #define count adsgasdgasdg
- using namespace std;
- long n;
- long iterations;
- vector<long> g[1<<20];
- long sub[1<<20];
- long k;
- void dfs(long v)
- {
- vector<long> sons;
- for (int i=0;i<g[v].size();i++)
- {
- long id=g[v][i];
- dfs(id);
- sons.push_back(id);
- }
- for (int i=0;i<sons.size();i++)
- {
- iterations+=k*sub[v];
- sub[v]+=sub[sons[i]];
- if (sub[v]>k)sub[v]=k;
- }
- sub[v]++;
- }
- int main(){
- //freopen("k.in","r",stdin);
- //freopen("k.out","w",stdout);
- //freopen("C:/input.txt","r",stdin);
- //freopen("C:/output.txt","w",stdout);
- ios_base::sync_with_stdio(0);
- //cin.tie(0);
- cin>>n;
- cin>>k;
- for (int i=1;i<=k;i++)
- {
- g[i].push_back(i+1);
- }
- for (int i=k+2;i<=n;i++)
- {
- g[1].push_back(i);
- }
- dfs(1);
- cout<<iterations<<endl;
- /*
- for (int i=1;i<=n;i++)
- cout<<sub[i]<<" ";*/
- cin.get();cin.get();
- return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement