結果

問題 No.826 連絡網
ユーザー kotamanegi
提出日時 2019-05-03 21:53:53
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 930 ms / 2,000 ms
コード長 2,564 bytes
コンパイル時間 1,152 ms
コンパイル使用メモリ 102,844 KB
実行使用メモリ 30,716 KB
最終ジャッジ日時 2024-11-24 02:21:22
合計ジャッジ時間 8,954 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define eps 0.000001
#define LONG_INF 10000000000000
#define GOLD 1.61803398874989484820458
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
unsigned long xor128() {
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
long long visited[2000000] = {};
long long nekoi[2000000] = {};
long long heas[2000000] = {};
int sosuu[2000000] = {};
int main() {
	int n, k;
	cin >> n >> k;
	if (k == 1) {
		cout << 1 << endl;
		return 0;
	}
	visited[k] = 1;
	heas[0] = k;
	int now_itr = 0;
	int max_itr = 1;
	vector<int> sosuu_list;
	for (int i = 2; i <= n; ++i) {
		int ok = 1;
		for (int q = 2; q <= sqrt(i); ++q) {
			if (i % q == 0) {
				ok = 0;
				break;
			}
		}
		if (ok == 1) {
			sosuu_list.push_back(i);
			sosuu[i] = 1;
		}
	}
	while (now_itr < max_itr) {
		int next = heas[now_itr];
		now_itr++;
		int nya = next;
		if (sosuu[nya] == 1&&nekoi[nya] == 0) {
			nekoi[nya] = 1;
			for (int j = 1; j * nya <= n; ++j) {
				if (visited[j * nya] == 0) {
					visited[j * nya] = 1;
					heas[max_itr] = (j * nya);
					max_itr++;
				}
				nekoi[j * nya] = 1;
			}
		}
		for (int tea = 0;sosuu_list[tea] <= sqrt(next); ++tea) {
			int i = sosuu_list[tea];
			if (next % i == 0) {
				int nya = i;
				if (sosuu[nya] == 1&&nekoi[nya] == 0) {
					nekoi[nya] = 1;
					for (int j = 1; j * nya <= n; ++j) {
						if (visited[j * nya] == 0) {
							visited[j * nya] = 1;
							heas[max_itr] = (j * nya);
							max_itr++;
						}
						nekoi[j * nya] = 1;
					}
				}
				nya = next / i;
				if (sosuu[nya] == 1&&nekoi[nya] == 0) {
					nekoi[nya] = 1;
					for (int j = 1; j * nya <= n; ++j) {
						if (visited[j * nya] == 0) {
							visited[j * nya] = 1;
							heas[max_itr] = (j * nya);
							max_itr++;
						}
						nekoi[j * nya] = 1;
					}
				}
			}
		}
	}
	cout << max_itr << endl;
	return 0;
}
0