Problem:
Sliding GCD
Problem Statement
自然数の集合
S
に対して，集合
\{ GCD(T) | T ⊆ S, T は空でない \}
の要素数を
f(S)
とおく．
ここで，
GCD(T)
は
T
に含まれるすべての数を割り切るような最大の整数である．
特に，
T
が一つの整数
a
のみからなるときは
GCD(\{a\}) = a
であることに注意せよ．
i = 1, 2, . . ., N - W+1
に対して
f(\{i, i+1, . . ., i+W - 1\})
を求めよ．
Input
入力は以下の形式に従う．与えられる数は全て整数である．
N
W
Constraints
1 ≦ W ≦ N ≦ 10^5
Output
i = 1, 2, . . ., N-W+1
のときの
f(\{i, i+1, . . ., i+W-1\})
の値を半角スペース区切りで 1 行に出力せよ．
Sample Input 1
10 2
Output for the Sample Input 1
2 3 3 3 3 3 3 3 3
GCD(\{1\}) = 1, GCD(\{2\}) = 2, GCD(\{1,2\}) = 1
となるから
f(\{1,2\}) = 2
である．
Sample Input 2
30 7
Output for the Sample Input 2
7 8 9 10 10 11 11 11 11 12 11 12 10 12 12 11 10 12 12 12 10 11 11 13

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll =long long;
using vll=vector<ll>;
using vvll=vector<vll>;
#define rep(i,n) for(ll i=0;i<n;i++)

bool E(ll L,ll R,ll N){
    if(L<=N&&N<=R)return 1;
    if((R/N)-(L-1)/N>=2)return 1;
    else return 0;
}
int main() {
    ll N,W;
    cin>>N>>W;
    ll an=W;
    cout<<an;
    rep(i,N-W){
        ll L=i+1,R=i+W+1,e;
        for(ll n=1;n*n<=L;n++){
            if(L%n==0){
                e=n;
                if((E(L,R-1,e))&&!E(L+1,R-1,e))an--;
                if(n*n==L)continue;
                e=L/n;
                if((E(L,R-1,e))&&!E(L+1,R-1,e))an--;
            }
        }
        for(ll n=1;n*n<=R;n++){
            if(R%n==0){
                e=n;
                if((!E(L+1,R-1,e))&&E(L+1,R,e))an++;
                if(n*n==R)continue;
                e=R/n;
                if((!E(L+1,R-1,e))&&E(L+1,R,e))an++;
            }
        }
        cout<<" "<<an;
    }
    cout<<endl;
}
accuracy: 1
time_ms: 300
memory_kb: 3420
final_rank: 16

code_snippet: #include <cmath>
#include <vector>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <climits>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cfloat>
#include <numeric>
#include <random>
#include <sstream>
#include <bitset>
#include <complex>
#include <chrono>
#include <cassert>

using namespace std;

vector<int> divisor(int value) {
	vector<int> result{ 1 };
	for (auto p = 2LL; p * p <= value; ++p) {
		if (value % p == 0) {
			int e{ 0 };
			while (value % p == 0) {
				++e;
				value /= p;
			}
			const auto size = result.size();
			for (auto i = 0; i < size; ++i) {
				result.push_back(result[i] * p);
				for (auto j = 1; j < e; ++j) {
					result.push_back(result.back() * p);
				}
			}
		}
	}
	if (value > 1) {
		const auto size = result.size();
		for (auto i = 0; i < size; ++i) {
			result.push_back(result[i] * value);
		}
	}
	return result;
}
int main() {
	int n, w; cin >> n >> w;
	unordered_set<int> set;
	vector<int> result; result.reserve(n - w + 1);
	for (auto i = 1; i <= w; ++i) {
		set.insert(i);
	}
	result.push_back(set.size());
	for (auto i = 2; i <= n - w + 1; ++i) {
		const auto remove = i - 1;
		const auto add = i + w - 1;
		const auto lower = i;
		const auto upper = i + w - 1;
		for (const auto d : divisor(remove)) {
			if (lower <= d && d <= upper) continue;
			if (lower <= upper / d * d - d) continue;
			set.erase(d);
		}
		for (const auto d : divisor(add)) {
			if (lower <= d && d <= upper) {
				set.insert(d); continue;
			}
			if (lower <= upper / d * d - d) {
				set.insert(d); continue;
			}
		}
		result.push_back(set.size());
	}
	for (auto i = 0; i < result.size(); ++i) {
		if (i > 0) cout << ' ';
		cout << result[i];
	}
	cout << '\n';
}
accuracy: 1
time_ms: 140
memory_kb: 7036
final_rank: 13

code_snippet: #include "bits/stdc++.h"
using namespace std;
#define FOR(i,s,t) for(int i = s; i < t; i++)
using LL = long long;
using ll = long long;

vector<int>divs(int n) {
    vector<int>a;
    for (LL i = 1; i*i <= n; i++) {
        if (n%i != 0)continue;
        int d = n / i;
        a.push_back(i);
        if (n%i == 0 && i != d) {
            a.push_back(d);
        }
    }
    return a;
}

int cnt[100005];
#define SZ(a) (int)a.size()
#define DEBUGL(x) cerr<<#x":="<<x<<endl
#define DEBUGS(x) cerr<<#x":="<<x<<" "
#define ENDL cerr<<endl
template <typename Monoid>
struct SegmentTree {
    using nd = typename Monoid::type;
    const int ARY_SIZE;
    vector<nd>node;
public:
    SegmentTree(int n) :ARY_SIZE(n), node(2 * ARY_SIZE, Monoid::id()) {}
    inline void update(int i, const nd val) {
        i += ARY_SIZE; node[i] =(val);
        while (i > 1) {
            i >>= 1; node[i] = Monoid::op(node[i << 1], node[(i << 1) + 1]);
        }
    }
    inline nd query(int l, int r) {
        if (l >= r)return Monoid::id();
        nd vl = Monoid::id(), vr = Monoid::id();
        for (l += ARY_SIZE, r += ARY_SIZE; l != r; l >>= 1, r >>= 1) {
            if (l & 1) {
                vl = Monoid::op(vl, node[l++]);
            }
            if (r & 1) {
                vr = Monoid::op(node[--r], vr);
            }
        }
        return Monoid::op(vl, vr);
    }
    nd operator[](int i) { return node[i + ARY_SIZE]; }
};
using PII = pair<int, int>;
struct Monoid {
    using type = PII;
    static type id() { return PII(0, 0); };
    static type op(const type&l, const type &r) {
        int la = l.first;
        int lb = r.first;
        int cnt = (la >= 2) + (lb >= 2);
        return PII(0, cnt + l.second + r.second);
    }
};

int main() {
    int N, W;
    while (cin >> N >> W) {
        SegmentTree<Monoid> seg(N+1);
        if (W == 1) {
            FOR(i, 0, N) {
                cout << 1 << " \n"[i == N - 1];
            }
            return 0;
        }
        
        vector<int>IQ1;
        int ans = W;
        IQ1.push_back(ans);
        ans = 0;
        FOR(i, 1, W + 1) {
            auto vecs = divs(i);
            for (auto it : vecs) {
                cnt[it]++;
                auto a = seg[it];
                seg.update(it, PII(a.first + 1, 0));
            }
        }
        ans = 0;
        FOR(R, W + 1, N+1) {
            int L = R - W;
            pair<int, int> range = { L + 1,R };
            auto outofrange = [&](int x) {
                if (range.first > x || range.second < x)return true;
                else return false;
            };
            
            // dec of L element
            {
                for (auto it : divs(L)) {
                    auto a = seg[it];
                    seg.update(it, PII(a.first - 1, 0));
                }
            }
            //
            
            
            // add R into set
            {
                for (auto it : divs(R)) {
                    auto a = seg[it];
                    seg.update(it, PII(a.first + 1, 0));
                }
            }
            // sum info
            auto res = seg.query(0, L + 1);
            int c = res.second;
            IQ1.push_back(c + W);
        }
        //IQ1.back()--;
        FOR(i, 0, SZ(IQ1)) {
            cout << IQ1[i] << " \n"[(i + 1) == SZ(IQ1)];
        }
    }
    
}
accuracy: 1
time_ms: 410
memory_kb: 5060
final_rank: 18

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100005

int N,W;
int count_table[NUM];
int ans[NUM];
vector<int> G[NUM];

int main(){

	scanf("%d %d",&N,&W);

	//約数の集合を作る
	for(int base = 1; base <= N; base++){
		for(int to = base; to <= N; to += base){
			G[to].push_back(base);
		}
	}

	for(int i = 1; i <= N; i++){
		count_table[i] = 0;
	}

	for(int i = 1; i <= W; i++){

		for(int k = 0; k < G[i].size(); k++){
				count_table[G[i][k]]++;
		}
		count_table[i] += 2;
	}

	ans[1] = W;
	int tmp_num = W;

	for(int left = 2; left <= N-W+1; left++){

		count_table[left-1] -= 2;
		if(count_table[left-1] < 2)tmp_num--;

		for(int i = 0; i < G[left-1].size(); i++){

			count_table[G[left-1][i]]--;
			if(count_table[G[left-1][i]] == 1){
				tmp_num--;
			}
		}

		tmp_num++;
		count_table[left+W-1] += 2;

		for(int i = 0; i < G[left+W-1].size(); i++){
			count_table[G[left+W-1][i]]++;
			if(count_table[G[left+W-1][i]] == 2){

				tmp_num++;
			}
		}
		ans[left] = tmp_num;
	}

	printf("%d",ans[1]);

	for(int i = 2; i <= N-W+1; i++){
		printf(" %d",ans[i]);
	}
	printf("\n");

	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 14252
final_rank: 12

code_snippet: #include <bits/stdc++.h>

#define ll long long
#define llong long long
#define REP(i,n) for(auto i=0;i<n;++i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define ALL(v) v.begin(),v.end()
#define pb push_back

using namespace std;

//約数が現在の範囲で何個あるか
int divisor[100001];

//その値が範囲内に2個以上あるか
bool is_used[100001] = {};

//現在の範囲で2個以上あるものの総数
int num;


//値xの約数について、範囲に追加
void plus_divisor(int x){
  
  divisor[x]++;
  
  for(int i = 1; i * i <= x; ++i){
    if(x % i == 0){
      divisor[i]++; 
      if(i * i != x) divisor[x / i]++;
      if(divisor[i] >= 2 && !is_used[i]){
        num++;
        is_used[i] = true;
      }
      if(divisor[x / i] >= 2 && !is_used[x / i]){
        num++;
        is_used[x / i] = true;
      }
    }
  }
}

//値xの約数について、範囲から削除
void minus_divisor(int x){

  
  divisor[x]--;
  
  for(int i = 1; i * i <= x; ++i){
    if(x % i == 0){
      divisor[i]--; 
      if(i * i != x) divisor[x / i]--;
      if(divisor[i] < 2 && is_used[i]){
        num--;
        is_used[i] = false;
      }
      if(divisor[x / i] < 2 && is_used[x / i]){
        num--;
        is_used[x / i] = false;
      }
    }
  }
}

int main(){

  int n, w;
  cin >> n >> w;
  
  for(int i = 1; i <= w; ++i){
    plus_divisor(i);
  }

  for(int i = 1; i <= n - w + 1; ++i){
    cout << num;
    if(i != n - w + 1){
      minus_divisor(i); plus_divisor(i+w);
      cout << " ";
    }else{
      cout << "\n";
    }
  }

  return 0;
}
accuracy: 1
time_ms: 120
memory_kb: 3508
final_rank: 8

code_snippet: #define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
using namespace std;

int main(){
  int N, W;
  cin >> N >> W;
  vector<int> ans(N+2, 0);
  ans[0] = W;
  for(int i = 1; i <= W/2; ++i){
    ++ans[i+1];
  }
  for(int i = W/2+1; i < W; ++i){
    for(int j = 3; j*i <= N; ++j){
      ++ans[j*i-W+1];
      --ans[j*i-W+1+W-i];
    }
  }
  for(int i = 1; i <= N-W+2; ++i){
    ans[i] += ans[i-1];
  }
  cout << ans[1];
  for(int i = 2; i <= N-W+1; ++i) cout << " " << ans[i];
  cout << endl;
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3096
final_rank: 3

code_snippet: #define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
using namespace std;

int main(){
  int N, W;
  cin >> N >> W;
  vector<int> ans(2*(N), 0);
  ans[0] = W;
  for(int i = 1; i <= W/2; ++i){
    ++ans[i+1];
  }
  for(int i = W/2+1; i < W; ++i){
    for(int j = 3; j*i <= N; ++j){
      ++ans[j*i-W+1];
      --ans[j*i-W+1+W-i];
    }
  }
  for(int i = 1; i <= N-W+2; ++i){
    ans[i] += ans[i-1];
  }
  cout << ans[1];
  for(int i = 2; i <= N-W+1; ++i) cout << " " << ans[i];
  cout << endl;
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3620
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, W;
    cin >> N >> W;
    const int H = W / 2;
    vector<int> imos(N + 1, 0);
    imos[1] = H;
    for (int j = H + 1; j < N + W; j++) {
        imos[max(1, j - W + 1)]++;
        if (j + 1 <= N) { imos[j + 1]--; }
    }
    for (int j = H + 1; j < W; j++) {
        for (int k = 1; k * j + 2 * j - W + 1 <= N; k++) {
            imos[k * j + 2 * j - W + 1]++;
            if (k * j + j + 1 <= N) { imos[k * j + j + 1]--; }
        }
    }
    for (int i = 1; i <= N - W + 1; i++) { imos[i] += imos[i - 1], cout << (i == 1 ? "" : " ") << imos[i]; }
    cout << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3096
final_rank: 3

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n,w;
  cin>>n>>w;
  if(w==1){
    for(Int i=0;i<n;i++){
      if(i) cout<<" ";
      cout<<1;
    }
    cout<<endl;
    return 0;
  };

  vector<Int> v(n+1,0);
  Int ans=0;
  auto inc=[&](Int x){
    if(v[x]++==0) ans++;
  };
  auto dec=[&](Int x){
    if(--v[x]==0) ans--;
  };
  vector<vector<Int> > div(n+1);
  for(Int i=1;i<=n;i++)
    for(Int j=i;j<=n;j+=i)
      div[j].emplace_back(i);
  
  
  for(Int i=1;i<=w;i++)
    for(Int j:div[i]) inc(j);
  
  cout<<ans;
  for(Int i=w+1;i<=n;i++){
    Int p=i-w;
    for(Int j:div[i])
      if(p<=i-j) inc(j);    
    for(Int j:div[p])
      if(p+j<=i) dec(j);
    inc(i);
    dec(p);
    cout<<" "<<ans;
  }
  cout<<endl;
  return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 19668
final_rank: 14

code_snippet: #include <iostream>
#include <algorithm>
using namespace std;
int N, W, s[200009];
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> N >> W;
	int ret = 0;
	for (int i = W / 2 + 1; i < W; i++) {
		for (int j = 2 * i - W + 1, k = 1; j <= N - W + 1 || k == 1; j += i, k++) {
			int l = j, r = j + W - i;
			if (j == 2 * i - W + 1) l = 1;
			s[l]++, s[r]--;
		}
	}
	for (int i = 1; i <= N - W + 1; i++) {
		if (i >= 2) cout << ' ';
		s[i] += s[i - 1];
		cout << s[i] + W / 2 + min(i, W);
	}
	cout << "\n";
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3572
final_rank: 5

code_snippet: #include<iostream>

using namespace std;

int main(){
  int N,W;
  cin>>N>>W;
  int c=0;
  int a[100001]={};
  for(int i=1;i<=N;i++){
    if(W<2*i&&i<W){
      a[i+1]+=i*3<=i+1+W-1;
      for(int j=i;j<=2*N;j+=i){
	int x=j-W+1;
	if(x>i+1&&x<=N){
	  a[x]++;
	}
	if(i+1<j+1&&j+1<=N){
	  a[j+1]--;
	}
      }
    }else if(i<W){
      a[i+1]++;
    }
  }
  for(int i=1;;i++){
    cout<<c+W;
    if(i==N-W+1){
      cout<<endl;
      break;
    }else{
      cout<<' ';
      c+=a[i+1];
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 1560
final_rank: 1

code_snippet: #include <set>
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <map>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int cnt[100010];

set<int> divisor(int N){
  set<int> res;
  for(int i=1;i*i<=N;i++){
    if(N%i==0){
      res.insert(i);
      res.insert(N/i);
    }
  }
  return res;
}

int main(){
  // ifstream cin("in.txt");
  int N,W;
  cin>>N>>W;
  int ans=0;
  // [1,W]の値について、約数を計算
  for(int i=1;i<=W;i++){
    set<int> s=divisor(i);
    for(set<int>::iterator it=s.begin();it!=s.end();it++){
      int num=*it;
      cnt[num]++;
      // 今回入ってきた数字は無条件に増える
      if(num==i)ans++;
      else{
        if(!(1<=num&&num<=i)&&cnt[num]==2)ans++;
      }
    }
  }
  cout<<ans;
  for(int i=0;i<N-W;i++){
    // for(int j=0;j<10;j++)
    //   cout<<cnt[j]<<" ";cout<<endl;
    {
      set<int> s=divisor(W+i+1);
      for(set<int>::iterator it=s.begin();it!=s.end();it++){
        int num=*it;
        cnt[num]++;
        if(num==W+i+1)ans++;
        else if(!(i+1<=num&&num<=W+i+1)&&cnt[num]==2)ans++;
      }
    }
    {
      set<int> s=divisor(i+1);
      for(set<int>::iterator it=s.begin();it!=s.end();it++){
        int num=*it;
        cnt[num]--;
        // 今回出て行った数字が維持できるかどうか
        if(num==i+1){
          if(cnt[num]<2)ans--;
        }
        // そうでない場合
        else{
          if(cnt[num]==1)ans--;
        }
      }
    }
    cout<<" "<<ans;
  }
  cout<<endl;
  
  return 0;
}
accuracy: 1
time_ms: 310
memory_kb: 1588
final_rank: 15

code_snippet: #include<iostream>
#include<vector>
using namespace std;

int main(){
  int n,w;
  bool table[100100];
  int f[1000],num;

  cin >> n >> w;
  int cnt = w;
  cout << cnt << (w==n?"\n":" ");
  for(int i=1;i<=w;i++)table[i] = true;
  for(int i=w+1;i<=n;i++)table[i] = false;

  for(int z=w+1;z<=n;z++){
    int prv = z-w;
    num = 0;
    for(int i=1;i*i<=prv;i++){
      if(prv%i==0){
	f[num++] = i;
	if(i*i!=prv)f[num++] = prv/i;
      }
    }

    for(int i=0;i<num;i++){
      if(!table[f[i]])continue;
      int pre = (prv+1)/f[i];
      if((prv+1)%f[i]!=0)pre++;
      int suf = (z-1)/f[i];
      if(suf-pre<=0){
	table[f[i]] = false;
	cnt--;
      }
    }
    
    num = 0;
    for(int i=1;i*i<=z;i++){
      if(z%i==0){
	f[num++] = i;
	if(i*i!=z)f[num++] = z/i;
      }
    }
    
    for(int i=0;i<num;i++){
      if(table[f[i]])continue;
      int pre = (prv+1)/f[i];
      if((prv+1)%f[i]!=0)pre++;
      int suf = (z-1)/f[i];
      if(suf-pre>=0){
	table[f[i]] = true;
	cnt++;
      }
    }
    table[z] = true; cnt++;

    cout << cnt << (z==n?"\n":" ");
  }
}
accuracy: 1
time_ms: 180
memory_kb: 1264
final_rank: 9

code_snippet: #include<iostream>
#include<vector>
using namespace std;

int main(){
  int n,w;
  bool table[100100];
  vector<int> f;

  cin >> n >> w;
  int cnt = w;
  cout << cnt << (w==n?"\n":" ");
  for(int i=1;i<=w;i++)table[i] = true;
  for(int i=w+1;i<=n;i++)table[i] = false;

  for(int z=w+1;z<=n;z++){
    int prv = z-w;
    f.clear();
    for(int i=1;i*i<=prv;i++){
      if(prv%i==0){
	f.push_back(i);
	if(i*i!=prv)f.push_back(prv/i);
      }
    }

    for(int i=0;i<f.size();i++){
      if(!table[f[i]])continue;
      int pre = (prv+1)/f[i];
      if((prv+1)%f[i]!=0)pre++;
      int suf = (z-1)/f[i];
      if(suf-pre<=0){
	table[f[i]] = false;
	cnt--;
      }
    }
    
    f.clear();
    for(int i=1;i*i<=z;i++){
      if(z%i==0){
	f.push_back(i);
	if(i*i!=z)f.push_back(z/i);
      }
    }
    
    for(int i=0;i<f.size();i++){
      if(table[f[i]])continue;
      int pre = (prv+1)/f[i];
      if((prv+1)%f[i]!=0)pre++;
      int suf = (z-1)/f[i];
      if(suf-pre>=0){
	table[f[i]] = true;
	cnt++;
      }
    }
    table[z] = true; cnt++;

    cout << cnt << (z==n?"\n":" ");
  }
}
accuracy: 1
time_ms: 180
memory_kb: 1320
final_rank: 10

code_snippet: #include<iostream>
#include<set>
#include<vector>
using namespace std;

int main(){
  int n,w;
  set<int> s;
  vector<int> f;

  cin >> n >> w;
  cout << w << (w==n?"\n":" ");
  for(int i=1;i<=w;i++)s.insert(i);

  for(int z=w+1;z<=n;z++){
    int prv = z-w;
    f.clear();
    for(int i=1;i*i<=prv;i++){
      if(prv%i==0){
	f.push_back(i);
	if(i*i!=prv)f.push_back(prv/i);
      }
    }

    for(int i=0;i<f.size();i++){
      if(s.find(f[i])==s.end())continue;
      int pre = (prv+1)/f[i];
      if((prv+1)%f[i]!=0)pre++;
      int suf = (z-1)/f[i];
      if(suf-pre<=0)s.erase(f[i]);
    }

    f.clear();
    for(int i=1;i*i<=z;i++){
      if(z%i==0){
	f.push_back(i);
	if(i*i!=z)f.push_back(z/i);
      }
    }

    s.insert(z);
    for(int i=0;i<f.size();i++){
      if(s.find(f[i])!=s.end())continue;
      int pre = (prv+1)/f[i];
      if((prv+1)%f[i]!=0)pre++;
      int suf = (z-1)/f[i];
      if(suf-pre>=0)s.insert(f[i]);
    }

    cout << s.size() << (z==n?"\n":" ");
  }
}
accuracy: 1
time_ms: 290
memory_kb: 5880
final_rank: 17

code_snippet: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;

#define DE 1
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(__typeof__(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}


const int MAX = 100100;
int N, W;
int con[MAX];

int main() {
    //freopen( "/Users/macuser/Documents/Programming/Contest/input.in", "r", stdin );
    
    while (cin >> N >> W) {
        memset(con, 0, sizeof(con));
        int geta = (W-1)/2;
        for (int d = (W+1)/2; d <= W-1; ++d) {
            con[1]++; con[d+1]--;
            for (int i = 2; i*d <= N; ++i) {
                int left = (i+1)*d-W+1, right = i*d;
                con[left]++; con[right+1]--;
            }
        }
         
        for (int i = 1; i <= N-W+1; ++i) {
            con[i+1] += con[i];
            int res = geta + con[i] + min(i, W);
            //cout << i << " : " << geta << ", " << con[i] << ", " << res << endl;
            cout << res;
            if (i != N-W+1) cout << " ";
        }
        cout << endl;
    }
    
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1564
final_rank: 2

code_snippet: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

vector<int> divisor[100001];
int cnt[100001];
bool f[100001];

int main() {
  const int N = 100000;
  for (int i=1; i<=N; ++i) {
    for (int j=i; j<=N; j+=i)
      divisor[j].push_back(i);
  }
  int w,n;
  while(cin>>n>>w) {
    int ans = w;
    for (int i=1; i<=w; ++i) {
      f[i] = 1;
      FOR(it, divisor[i]) {
        if (++cnt[*it] == 2 && !f[i]) ans++;
      }
    }
    cout << ans;
    for (int i=1; i<=n-w; ++i) {
      f[i+w] = 1;
      ans++;
      FOR(it, divisor[i])
        if (--cnt[*it] == 1 && !f[*it]) ans--;
      FOR(it, divisor[i+w])
        if (++cnt[*it] == 2 && !f[*it]) ans++;
      f[i] = 0;
      if (cnt[i] < 2) ans--;
      cout << " " << ans;
    }
    cout << endl;
  }
}
accuracy: 1
time_ms: 70
memory_kb: 12048
final_rank: 11

code_snippet: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int N,W,w;
vi d[100010];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>N>>W;
	w=W/2;
	vi ans;
	rep2(i,1,min(w+2,N-W+2)){
		ans.pb(i+W-1);
	}
	rep2(i,w+1,W){
		for(int j=i;j<=N;j+=i){
			d[j].pb(i);
		}
	}
	int res=ans[sz(ans)-1];
	rep2(i,w+2,N-W+2){
		int in=i+W-1,out=i-1;
		int hi=min(i-1,W-1);
		rep(j,sz(d[in]))if(d[in][j]<=hi)res++;
		rep(j,sz(d[out]))if(d[out][j]<=hi)res--;
		if(out<W)res++;
		ans.pb(res);
	}
	rep(i,sz(ans))cout<<ans[i]<<(i==sz(ans)-1?"\n":" ");
}
accuracy: 1
time_ms: 10
memory_kb: 5616
final_rank: 7

code_snippet: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int N,W,w;
vi d[100010];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>N>>W;
	w=W/2;
	vi ans;
	rep2(i,1,w+2){
		ans.pb(i+W-1);
	}
	rep2(i,w+1,W){
		for(int j=i;j<=N;j+=i){
			d[j].pb(i);
		}
	}
	int res=ans[sz(ans)-1];
	rep2(i,w+2,N-W+2){
		int in=i+W-1,out=i-1;
		int hi=min(i-1,W-1);
		rep(j,sz(d[in]))if(d[in][j]<=hi)res++;
		rep(j,sz(d[out]))if(d[out][j]<=hi)res--;
		if(out<W)res++;
		ans.pb(res);
	}
	rep(i,sz(ans))cout<<ans[i]<<(i==sz(ans)-1?"\n":" ");
}
accuracy: 0.09090909090909091
time_ms: 10
memory_kb: 5280
final_rank: 20

code_snippet: #include<stdio.h>
#include<algorithm>
using namespace std;
pair<int,int> event[5000000];
int now[100001];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	int at=0;
	for(int i=1;i<=a;i++){
		event[at++]=make_pair(i-b+1,i);
		event[at++]=make_pair(i+1,-i);
		for(int j=1;j*j<=i;j++){
			if(i%j==0){
				int c=i/j;
				if(j<b){
					event[at++]=make_pair(i-b+1,j);
					event[at++]=make_pair(i-j+1,-j);
					event[at++]=make_pair(i+j-b+1,j);
					event[at++]=make_pair(i+1,-j);
				}
				if(c<b){
					event[at++]=make_pair(i-b+1,c);
					event[at++]=make_pair(i-c+1,-c);
					event[at++]=make_pair(i+c-b+1,c);
					event[at++]=make_pair(i+1,-c);
				}
			}
		}
	}
	std::sort(event,event+at);
	int ret=0;
	int right=0;
	int left=0;
	for(int i=1;i<=a-b+1;i++){
		while(event[right].first<=i){
			if(event[right].second>0){
				now[event[right].second]++;
				if(now[event[right].second]==1)ret++;
			}
			right++;
		}
		while(event[left].first<=i){
			if(event[left].second<0){
				now[-event[left].second]--;
				if(now[-event[left].second]==0)ret--;
			}
			left++;
		}
		//for(int j=1;j<=10;j++)printf("%d ",now[j]);

		printf("%d",ret);
		if(i<a-b+1)printf(" ");
		else printf("\n");
	}
}
accuracy: 1
time_ms: 460
memory_kb: 40484
final_rank: 19