Problem:
問題 E
Fox Number
問題文
きつねのしえるは数字について考えるのが好きである．ある日，しえるはこの世にねこの数字というものがあることを知り，自分もそのような数字が欲しくなってしまった．そこで，次の性質を満たす数字をとりあえず Fox Number と呼ぶことにした．
[性質]: 整数
N
は
k (≥ 1)
個の素数
p
1
, ..., p
k
と正整数
e
1
, ..., e
k
で，
p
1
< ... < p
k
，
e
1
≥ ... ≥ e
k
を満たすものによって
N = p
1
e
1
× ... ×  p
k
e
k
と書けるとき，Fox Number であると呼ぶことにする．
ところでしえるはこの性質をその場の思いつきで決めてしまったのでこれがどういう性質を持っているのか全くわかっていない．そこで，この数字の性質を調べるために区間
[A-B, A+B]
に含まれる Fox Number の個数を出力して欲しい．
入力形式
1
行目に以下の
2
つの整数が与えられる．
A
B
出力形式
1
行目に，
A-B
以上
A+B
以下の Fox Number の個数を出力せよ．
制約
1 ≤ A ≤ 10
12
0 ≤ B ≤ 5 × 10
5
入出力例
入力例 1
18 2
出力例 1
4
16 = 2
4
, 17 = 17
1
, 19 = 19
1
, 20 = 2
2
× 5
1
は Fox Number である．一方で
18 = 2 × 3
2
は Fox Number ではない．合計して
4
つの Fox Number がある．
入力例 2
100 10
出力例 2
18
入力例 3
123456 789
出力例 3
1464

Submitted solutions:

code_snippet: #include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <numeric>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>
std::vector<int> cal_primes() {
	std::vector<bool> is_prime(1000001, true);
	for (auto i = 2; i * i < is_prime.size(); ++i) {
		if (is_prime[i]) {
			for (auto j = i * i; j < is_prime.size(); j += i) {
				is_prime[j] = false;
			}
		}
	}
	std::vector<int> result;
	for (auto i = 2; i < is_prime.size(); ++i) {
		if (is_prime[i]) result.push_back(i);
	}
	return result;
}
int main() {
	const auto prime = cal_primes();
	long long int a; int b; std::cin >> a >> b;
	const auto min = std::max(2LL, a - b);
	const auto max = a + b;
	std::vector<int> last_exp(max - min + 1, INT_MAX);
	for (const auto p : prime) {
		int e = 0;
		long long int mul = 1;
		while ((min + mul - 1) / mul * mul <= max) {
			++e;
			mul *= p;
			for (auto i = (min + mul - 1) / mul; i * mul <= max; ++i) {
				if (i % p == 0) continue;
				if (last_exp[mul * i - min] >= e) last_exp[mul * i - min] = e;
				else last_exp[mul * i - min] = -1;
			}
		}
	}
	std::cout << std::count_if(last_exp.begin(), last_exp.end(), [](const int e) {return e != -1; }) << std::endl;
}
accuracy: 1
time_ms: 30
memory_kb: 7448
final_rank: 1

code_snippet: #include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <numeric>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>
std::vector<int> cal_primes() {
	std::vector<bool> is_prime(1000001, true);
	for (auto i = 2; i * i < is_prime.size(); ++i) {
		if (is_prime[i]) {
			for (auto j = i * i; j < is_prime.size(); j += i) {
				is_prime[j] = false;
			}
		}
	}
	std::vector<int> result;
	for (auto i = 2; i < is_prime.size(); ++i) {
		if (is_prime[i]) result.push_back(i);
	}
	return result;
}
int main() {
	const auto prime = cal_primes();
	long long int a; int b; std::cin >> a >> b;
	std::vector<int> last_exp(b * 2 + 1, INT_MAX);
	for (const auto p : prime) {
		int e = 0;
		long long int mul = 1;
		while ((a - b + mul - 1) / mul * mul <= a + b) {
			++e;
			mul *= p;
			for (auto i = (a - b + mul - 1) / mul; i * mul <= a + b; ++i) {
				if (i % p == 0) continue;
				if (last_exp[mul * i - (a - b)] >= e) last_exp[mul * i - (a - b)] = e;
				else last_exp[mul * i - (a - b)] = -1;
			}
		}
	}
	std::cout << std::count_if(last_exp.begin(), last_exp.end(), [](const int e) {return e != -1; }) << std::endl;
}
accuracy: 0.027777777777777776
time_ms: 30
memory_kb: 7284
final_rank: 14

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.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 1200000
#define HUGE_NUM 99999999999999

int main(){

	int limit;
	ll* table = new ll[NUM];

	for(int i=0; i < NUM;i++)table[i] = 1;
	table[0] = 0;
	table[1] = 0;

	limit = sqrt(NUM);

	for(int i=2;i<=limit;i++){
		if(table[i] == 1){
			for(int k=2*i;k < NUM; k += i){
				table[k] = 0;
			}
		}
	}

	int index = 0;
	ll* prime_table = new ll[550000];

	for(int i = 2; i < NUM; i++){
		if(table[i] == 1){
			prime_table[index++] = i;
		}
	}

	ll A,B;
	scanf("%lld %lld",&A,&B);

	ll left,right;

	if(A-B <= 2){
		left = 2;
	}else{
		left = A-B;
	}

	right = A+B;

	if(left > right){
		printf("0\n");
		return 0;
	}

	ll* check = new ll[right-left+1];
	for(int i = 0; i < right-left+1; i++){
		check[i] = HUGE_NUM;
	}

	bool* is_fox = new bool[right-left+1];
	for(int i = 0; i < right-left+1; i++)is_fox[i] = true;

	ll tmp,count,start;

	for(int i = 0; prime_table[i] <= sqrt(right); i++){

		if(left%prime_table[i] == 0){
			start = 0;
		}else{
			start = prime_table[i]*(left/prime_table[i]+1)-left;
		}

		if(left+start > right)continue;

		for(int k = start; k < right-left+1; k += prime_table[i]){

			if(!is_fox[k])continue;

			tmp = left+k;

			count = 0;

			while(tmp%prime_table[i] == 0){
				tmp /= prime_table[i];
				count++;
			}

			if(check[k] < count){
				is_fox[k] = false;
			}else{
				check[k] = count;
			}
		}
	}

	int ans = 0;

	for(int i = 0; i < right-left+1; i++){
		if(is_fox[i])ans++;
	}

	printf("%d\n",ans);

	return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 22080
final_rank: 6

code_snippet: #include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
long long A; int B;
int main() {
	cin >> A >> B;
	long long l = max(A - B, 2LL), r = A + B + 1;
	int p = sqrt(r);
	vector<long long> f(r - l);
	vector<bool> ok(r - l, true); vector<int> x(r - l, 999999999);
	for (int i = 0; i < r - l; i++) f[i] = l + i;
	for (int i = 2; i <= p; i++) {
		long long w = l / i * i;
		if (w < l) w += i;
		for (long long j = w; j < r; j += i) {
			int cnt = 0;
			while (f[j - l] % i == 0) f[j - l] /= i, cnt++;
			if (cnt >= 1) {
				if (x[j - l] < cnt) ok[j - l] = false;
				x[j - l] = cnt;
			}
		}
	}
	int ret = 0;
	for (int i = 0; i < r - l; i++) ret += (ok[i] ? 1 : 0);
	cout << ret << endl;
	return 0;
}
accuracy: 1
time_ms: 300
memory_kb: 14696
final_rank: 7

code_snippet: #include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
long long A; int B;
int main() {
	cin >> A >> B;
	long long l = max(A - B, 1LL), r = A + B + 1;
	int p = sqrt(r);
	vector<long long> f(r - l);
	vector<bool> ok(r - l, true); vector<int> x(r - l, 999999999);
	for (int i = 0; i < r - l; i++) f[i] = l + i;
	for (int i = 2; i <= p; i++) {
		long long w = l / i * i;
		if (w < l) w += i;
		for (long long j = w; j < r; j += i) {
			int cnt = 0;
			while (f[j - l] % i == 0) f[j - l] /= i, cnt++;
			if (cnt >= 1) {
				if (x[j - l] < cnt) ok[j - l] = false;
				x[j - l] = cnt;
			}
		}
	}
	int ret = 0;
	for (int i = 0; i < r - l; i++) ret += (ok[i] ? 1 : 0);
	cout << ret << endl;
	return 0;
}
accuracy: 0.027777777777777776
time_ms: 280
memory_kb: 14608
final_rank: 19

code_snippet: #include<iostream>
#include<vector>
using namespace std;
#define MAX_N 1000007
long long A, B, W[MAX_N], cnt; bool prime[MAX_N];
vector<short>V[MAX_N];
void primesieve() {
	for (int i = 2; i*i <= 1000000; i++) {
		for (int j = i*i; j <= 1000000; j += i) prime[j] = true;
	}
	for (int i = 0; i <= 1000000; i++)prime[i] ^= true;
}
int main() {
	cin >> A >> B; long long L = A - B, R = A + B; primesieve(); if (L <= 0)L = 1;
	for (long long i = L; i <= R; i++) { W[i - L] = i; }
	for (long long i = 2; i <= 1000000; i++) {
		if (prime[i] == false)continue;
		long long F = (L / i)*i; if ((L%i) > 0)F += i;
		for (long long j = F; j <= R; j += i) {
			int cnts = 0;
			while (W[j - L] % i == 0) { W[j - L] /= i; cnts++; }
			if (cnts >= 1) { V[j - L].push_back(cnts); }
		}
	}
	for (long long i = L; i <= R; i++) { if (W[i - L] >= 2 && W[i - L] != i)V[i - L].push_back(1); }
	for (long long i = L; i <= R; i++) {
		bool OK = true; if (i <= 1LL)OK = false;
		for (int j = 1; j < V[i - L].size(); j++) {
			if (V[i - L][j - 1] < V[i - L][j])OK = false;
		}
		if (OK == true)cnt++;
	}
	cout << cnt << endl;
	return 0;
}
accuracy: 1
time_ms: 440
memory_kb: 65376
final_rank: 11

code_snippet: #include<iostream>
#include<vector>
using namespace std;
#define MAX_N 1000007
long long A, B, W[MAX_N], cnt; bool prime[MAX_N];
vector<short>V[MAX_N];
void primesieve() {
	for (int i = 2; i*i <= 1000000; i++) {
		for (int j = i*i; j <= 1000000; j += i) prime[j] = true;
	}
	for (int i = 0; i <= 1000000; i++)prime[i] ^= true;
}
int main() {
	cin >> A >> B; long long L = A - B, R = A + B; primesieve();
	for (long long i = L; i <= R; i++) { W[i - L] = i; }
	for (long long i = 2; i <= 1000000; i++) {
		if (prime[i] == false)continue;
		long long F = (L / i)*i; if ((L%i) > 0)F += i;
		for (long long j = F; j <= R; j += i) {
			int cnts = 0;
			while (W[j - L] % i == 0) { W[j - L] /= i; cnts++; }
			if (cnts >= 1) { V[j - L].push_back(cnts); }
		}
	}
	for (long long i = L; i <= R; i++) { if (W[i - L] >= 2 && W[i - L] != i)V[i - L].push_back(1); }
	for (long long i = L; i <= R; i++) {
		bool OK = true;
		for (int j = 1; j < V[i - L].size(); j++) {
			if (V[i - L][j - 1] < V[i - L][j])OK = false;
		}
		if (OK == true)cnt++;
	}
	cout << cnt << endl;
	return 0;
}
accuracy: 0.027777777777777776
time_ms: 450
memory_kb: 65436
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

bool is_prime[2000000];
vector<ll> primes;
bool is_fox_number[11000000];
int cnt[11000000];

void Sieve(){
	fill_n(is_prime,2000000,true);
	is_prime[0]=is_prime[1]=false;
	for(int i=2; i<2000000; ++i){
		if(is_prime[i]){
			primes.push_back(i);
			for(int j=i*2; j<2000000; j+=i) is_prime[j]=false;
		}
	}
}

void Solve(){
	Sieve();
	ll a,b,l,h;
	cin >> a >> b;
	l=max(a-b,2LL);
	h=a+b+1;

	fill_n(is_fox_number,11000000,true);
	fill_n(cnt,11000000,INF);

	for(auto p:primes){
		ll x=(l+p-1)/p*p;
		if(p*p>h) break;
		while(x<h){
			if(!is_fox_number[x-l]){
				x+=p;
				continue;
			}
			
			ll tmp=x;
			int c=0;
			while(tmp%p==0){
				tmp/=p;
				++c;
			}

			if(c>cnt[x-l]) is_fox_number[x-l]=false;

			cnt[x-l]=c;
			x+=p;
		}
	}

	int ans=0;
	rep(i,0,h-l) ans+=is_fox_number[i];

	cout << ans << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 58996
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

bool is_prime[2000000];
vector<ll> primes;
bool is_fox_number[11000000];
int cnt[11000000];

void Sieve(){
	fill_n(is_prime,2000000,true);
	is_prime[0]=is_prime[1]=false;
	for(int i=2; i<2000000; ++i){
		if(is_prime[i]){
			primes.push_back(i);
			for(int j=i*2; j<2000000; j+=i) is_prime[j]=false;
		}
	}
}

void Solve(){
	Sieve();
	ll a,b,l,h;
	cin >> a >> b;
	l=max(a-b,2LL);
	h=a+b+1;

	fill_n(is_fox_number,11000000,true);
	fill_n(cnt,11000000,INF);

	for(auto p:primes){
		ll x=(l+p-1)/p*p;
		//if(x*x>h) break;
		while(x<h){
			if(!is_fox_number[x-l]){
				x+=p;
				continue;
			}
			
			ll tmp=x;
			int c=0;
			while(tmp%p==0){
				tmp/=p;
				++c;
			}

			if(c>cnt[x-l]) is_fox_number[x-l]=false;

			cnt[x-l]=c;
			x+=p;
		}
	}

	int ans=0;
	rep(i,0,h-l) ans+=is_fox_number[i];

	cout << ans << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}
accuracy: 1
time_ms: 120
memory_kb: 58160
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

bool is_prime[2000000];
vector<ll> primes;
bool is_fox_number[11000000];
int cnt[11000000];

void Sieve(){
	fill_n(is_prime,2000000,true);
	is_prime[0]=is_prime[1]=false;
	for(int i=2; i<2000000; ++i){
		if(is_prime[i]){
			primes.push_back(i);
			for(int j=i*2; j<2000000; j+=i) is_prime[j]=false;
		}
	}
}

void Solve(){
	Sieve();
	ll a,b,l,h;
	cin >> a >> b;
	l=max(a-b,2LL);
	h=a+b+1;

	fill_n(is_fox_number,11000000,true);
	fill_n(cnt,11000000,INF);

	for(auto p:primes){
		ll x=(l+p-1)/p*p;
		//if(x*x>h) break;
		while(x<h){
			if(!is_fox_number[x-l]){
				x+=p;
				continue;
			}
			
			ll tmp=x;
			int c=0;
			while(tmp%p==0){
				tmp/=p;
				++c;
			}

			if(c>cnt[x-(a-b)]) is_fox_number[x-l]=false;

			cnt[x-l]=c;
			x+=p;
		}
	}

	int ans=0;
	rep(i,0,h-l) ans+=is_fox_number[i];

	cout << ans << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}
accuracy: 0.05555555555555555
time_ms: 110
memory_kb: 58160
final_rank: 13

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

#define REP(i,n) for(int64_t i=0;i<(int64_t)(n);i++)

using namespace std;

bool is_valid(const vector<int>& fct, int64_t n) {
  int64_t old_h = 0;
  for (int p : fct) {
    int cnt = 0;
    while((n % p) == 0){
      n /= p;
      ++cnt;
    }
    if (cnt < old_h) return false;
    old_h = cnt;
  }
  return true;
}

int main() {
  int64_t a, b;
  cin >> a >> b;
  int64_t beg = max(a - b, int64_t(2));
  int64_t ed = a + b;
  vector<vector<int>> pl2(1000001);
  vector<int> ps(1100001,1);
  ps[0] = ps[1] = 0;
  int64_t i;
  for (i = 2; i * i * i * i <= ed; ++i) {
    if (ps[i] == 1) {
      int64_t offset = (i - (beg % i)) % i;
      for (int64_t k = offset; k <= 1000000; k += i) {
        pl2[k].push_back(i);
      }
      for (int64_t j = i * 2; j * j <= ed; j += i) {
        ps[j] = i;
      }
    }
  }
  for (; i * i <= ed; ++i) {
    if (ps[i] == 1) {
      int64_t offset = (i - (beg % i)) % i;
      for (int64_t k = offset; k <= 1000000; k += i) {
        pl2[k].push_back(i);
      }
      for (int64_t j = i * 2; j * j <= ed; j += i) {
        ps[j] = i;
      }
    }
  }
  int64_t cnt = 0;
  for (int64_t i = 0; i <= ed - beg; ++i) {
    auto fct = pl2[i];
    sort(begin(fct),end(fct),greater<int64_t>());
    if (is_valid(fct, beg+i)) {
      ++cnt;
    }
  }
  cout << cnt << endl;
  return 0;
}
accuracy: 1
time_ms: 460
memory_kb: 63608
final_rank: 12

code_snippet: #include<iostream>
#include<algorithm>

using namespace std;

int main(){
  const int N=1100000;
  static bool cmp[N+1]={true,true};
  for(int i=2;i<=N;i++){
    if(!cmp[i]){
      for(int j=i*2;j<=N;j+=i){
	cmp[j]=true;
      }
    }
  }
  static int le[1000001];
  fill(begin(le),end(le),1<<29);
  long long A,B;
  cin>>A>>B;
  for(int i=0;i<=N;i++){
    if(!cmp[i]){
      for(long long j=max<long long>(i,(A-B+i-1)/i*i);j<=A+B;j+=i){
	int x=j-(A-B);
	int e=0;
	for(long long c=j;c%i==0;c/=i,e++);
	le[x]=(le[x]>=e)?e:-1;
      }
    }
  }
  int ans=0;
  for(int i=0;i<B*2+1;i++){
    ans+=i+A-B>=2&&le[i]>0;
  }
  cout<<ans<<endl;
}
accuracy: 1
time_ms: 110
memory_kb: 6144
final_rank: 3

code_snippet: #include<iostream>
#include<algorithm>

using namespace std;

int main(){
  const int N=1000000;
  static bool cmp[N+1]={true,true};
  for(int i=2;i<=N;i++){
    if(!cmp[i]){
      for(int j=i*2;j<=N;j+=i){
	cmp[j]=true;
      }
    }
  }
  static int le[1000001];
  fill(begin(le),end(le),1<<29);
  long long A,B;
  cin>>A>>B;
  for(int i=0;i<=N;i++){
    if(!cmp[i]){
      for(long long j=(A-B+i-1)/i*i;j<=A+B;j+=i){
	int x=j-(A-B);
	int e=0;
	for(long long c=j;c%i==0;c/=i,e++);
	le[x]=(le[x]>=e)?e:-1;
      }
    }
  }
  int ans=0;
  for(int i=0;i<B*2+1;i++){
    ans+=le[i]>0;
  }
  cout<<ans<<endl;
}
accuracy: 0.027777777777777776
time_ms: 100
memory_kb: 6044
final_rank: 15

code_snippet: #include<iostream>
#include<algorithm>

using namespace std;

int main(){
  static bool cmp[1000001]={true,true};
  for(int i=2;i<=1000000;i++){
    if(!cmp[i]){
      for(int j=i*2;j<=1000000;j+=i){
	cmp[j]=true;
      }
    }
  }
  static int le[1000001];
  fill(begin(le),end(le),1<<29);
  long long A,B;
  cin>>A>>B;
  for(int i=0;i<=1000000;i++){
    if(!cmp[i]){
      for(long long j=(A-B+i-1)/i*i;j<=A+B;j+=i){
	int x=j-(A-B);
	int e=0;
	for(long long c=j;c%i==0;c/=i,e++);
	le[x]=(le[x]>=e)?e:-1;
      }
    }
  }
  int ans=0;
  for(int i=0;i<B*2+1;i++){
    ans+=le[i]>0;
  }
  cout<<ans<<endl;
}
accuracy: 0.027777777777777776
time_ms: 100
memory_kb: 6044
final_rank: 15

code_snippet: #include<stdio.h>
#include<algorithm>
using namespace std;
int dm[1100000];
int m[1100000];
int isp[1100000];
int prime[1100000];
int main(){
	int sz=0;
	isp[0]=isp[1]=-1;
	for(int i=2;i<1100000;i++){
		if(~isp[i]){
			isp[i]=1;
			prime[sz++]=i;
			for(int j=i+i;j<1100000;j+=i)isp[j]=-1;
		}
	}
	long long a,b;scanf("%lld%lld",&a,&b);
	long long L=max(1LL,a-b);
	long long R=a+b;
	int n=R-L+1;
	for(int i=0;i<n;i++)m[i]=9999999;
	for(int i=1;(long long)prime[i]*prime[i]<=R;i++){
		int E=prime[i-1];
		for(long long j=(L+E-1)/E*E;j<=R;j+=E){
			long long now=j;
			int time=0;
			while(now%E==0){
				now/=E;time++;
			}
			m[j-L]=min(m[j-L],time);
		}
		int D=prime[i];
		long long S=L/D/D*D*D;
		long long T=R/D/D*D*D;
		while(S<L)S+=(long long)D*D;
		while(T>R)T-=(long long)D*D;
		for(long long j=S;j<=T;j+=(long long)D*D){
			long long now=j;
			int time=0;
			while(now%D==0){
				now/=D;time++;
			}
			if(m[j-L]<time){
			//	printf("%lld %d\n",j,i);
				dm[j-L]=1;
			}
		}
	}
	int ret=n;
	if(L==1LL)dm[0]=1;
	for(int i=0;i<n;i++)if(dm[i])ret--;
	printf("%d\n",ret);
}
accuracy: 1
time_ms: 120
memory_kb: 14064
final_rank: 5

code_snippet: #include<stdio.h>
#include<algorithm>
using namespace std;
int dm[1100000];
int m[1100000];
int isp[1100000];
int prime[1100000];
int main(){
	int sz=0;
	isp[0]=isp[1]=-1;
	for(int i=2;i<1100000;i++){
		if(~isp[i]){
			isp[i]=1;
			prime[sz++]=i;
			for(int j=i+i;j<1100000;j+=i)isp[j]=-1;
		}
	}
	long long a,b;scanf("%lld%lld",&a,&b);
	long long L=max(1LL,a-b);
	long long R=a+b;
	int n=R-L+1;
	for(int i=0;i<n;i++)m[i]=9999999;
	for(int i=1;(long long)prime[i]*prime[i]<=R;i++){
		int E=prime[i-1];
		for(long long j=(L+E-1)/E*E;j<=R;j+=E){
			long long now=j;
			int time=0;
			while(now%E==0){
				now/=E;time++;
			}
			m[j-L]=min(m[j-L],time);
		}
		int D=prime[i];
		long long S=L/D/D*D*D;
		long long T=R/D/D*D*D;
		while(S<L)S+=(long long)D*D;
		while(T>R)T-=(long long)D*D;
		for(long long j=S;j<=T;j+=(long long)D*D){
			long long now=j;
			int time=0;
			while(now%D==0){
				now/=D;time++;
			}
			if(m[j-L]<time){
			//	printf("%lld %d\n",j,i);
				dm[j-L]=1;
			}
		}
	}
	int ret=n;
	for(int i=0;i<n;i++)if(dm[i])ret--;
	printf("%d\n",ret);
}
accuracy: 0.027777777777777776
time_ms: 110
memory_kb: 14064
final_rank: 17

code_snippet: #include<stdio.h>
#include<algorithm>
using namespace std;
long long d[1100000];
int dm[1100000];
int m[1100000];
int isp[1100000];
int prime[1100000];
int main(){
	int sz=0;
	isp[0]=isp[1]=-1;
	for(int i=2;i<1100000;i++){
		if(~isp[i]){
			isp[i]=1;
			prime[sz++]=i;
			for(int j=i+i;j<1100000;j+=i)isp[j]=-1;
		}
	}
	long long a,b;scanf("%lld%lld",&a,&b);
	long long L=max(1LL,a-b);
	long long R=a+b;
	int n=R-L+1;
	for(int i=0;i<n;i++)d[i]=L+i;
	for(int i=0;i<n;i++)m[i]=9999999;
	for(int i=1;(long long)prime[i]*prime[i]<=R;i++){
		int E=prime[i-1];
		for(long long j=(L+E-1)/E*E;j<=R;j+=E){
			long long now=j;
			int time=0;
			while(now%E==0){
				now/=E;time++;
			}
			m[j-L]=min(m[j-L],time);
		}
		int D=prime[i];
		long long S=L/D/D*D*D;
		long long T=R/D/D*D*D;
		while(S<L)S+=(long long)D*D;
		while(T>R)T-=(long long)D*D;
		long long div=(long long )D*D;
		for(long long j=S;j<=T;j+=(long long)D*D){
			long long now=j;
			int time=0;
			while(now%D==0){
				now/=D;time++;
			}
			if(m[j-L]<time){
			//	printf("%lld %d\n",j,i);
				dm[j-L]=1;
			}
		}
	}
	int ret=n;
	for(int i=0;i<n;i++)if(dm[i])ret--;
	printf("%d\n",ret);
}
accuracy: 0.027777777777777776
time_ms: 120
memory_kb: 22268
final_rank: 18

code_snippet: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int count_fox_number(ll a, ll b){
  if(a < 2) a = 2;
  if(!(a < b)) return 0;
  int ans = b - a;
  bool prime_small[1000100];
  for(int i = 2; (ll) i * i < b; i++) prime_small[i] = true;
  int cnt_pow[1000100];
  REP(i, b - a) cnt_pow[i] = INF;
  for(int i = 2; (ll)i * i < b; i++){
    if(prime_small[i]){
      for(int j = 2 * i; (ll) j * j < b; j += i) prime_small[j] = false;
      for(ll j = max(2LL, (a + i - 1)/i) * i; j < b; j += i){
        if(cnt_pow[j - a] == -1) continue;
        ll t = j;
        int cnt = 0;
        while(t % i == 0){
          t /= i;
          cnt++;
        }
        assert(cnt != 0);
        if(cnt_pow[j - a] < cnt){
          cnt_pow[j - a] = -1;
          ans--;
        }else{
          cnt_pow[j - a] = cnt;
        }
      }
    }
  }
  return ans;
}

int main(){
  ll a, b;
  while(cin>>a>>b){
    cout<<count_fox_number(a - b, a + b + 1)<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 6040
final_rank: 2

code_snippet: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int count_fox_number(ll a, ll b){
  if(a < 2) a = 2;
  if(!(a < b)) return 0;
  int ans = b - a;
  bool prime_small[1000100] = {};
  //for(int i = 2; (ll) i * i < b; i++) prime_small[i] = true;
  int cnt_pow[1000100];
  REP(i, b - a) cnt_pow[i] = INF;
  for(int i = 2; (ll)i * i < b; i++){
    if(!prime_small[i]){
      for(int j = 2 * i; (ll) j * j < b; j += i) prime_small[j] = true;
      for(ll j = max(2LL, (a + i - 1)/i) * i; j < b; j += i){
        if(cnt_pow[j - a] == -1) continue;
        ll t = j;
        int cnt = 0;
        while(t % i == 0){
          t /= i;
          cnt++;
        }
        assert(cnt != 0);
        if(cnt_pow[j - a] < cnt){
          cnt_pow[j - a] = -1;
          ans--;
        }else{
          cnt_pow[j - a] = cnt;
        }
      }
    }
  }
  return ans;
}

int main(){
  ll a, b;
  while(cin>>a>>b){
    cout<<count_fox_number(a - b, a + b + 1)<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 120
memory_kb: 6052
final_rank: 4

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

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#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 pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

bool isp[1000011];
int last[1000011];
ll cur[1000011];
ll A,B,a,b;

int main(){
	cin>>A>>B;
	a=max(2LL,A-B);
	b=A+B;
	fill(isp,isp+1000011,1);
	fill(last,last+2*B+1,INF);
	for(ll i=a;i<=b;i++)cur[i-a]=i;
	for(ll i=2;i*i<=b;i++){
		if(isp[i]){
			for(ll j=2*i;j*j<=b;j+=i) isp[j]=0;
			for(ll j=max(2LL,(a+i-1)/i)*i;j<=b;j+=i){
				if(last[j-a]>-1){
					int y=0;
					while(cur[j-a]%i==0)cur[j-a]/=i,y++;
					if(last[j-a]<y)last[j-a]=-1;
					else last[j-a]=y;
				}
			}
		}
	}
	int ans=0;
	for(ll i=a;i<=b;i++)ans+=last[i-a]>-1;
	cout<<ans<<endl;
}
accuracy: 1
time_ms: 340
memory_kb: 13000
final_rank: 8