結果

問題 No.826 連絡網
ユーザー Bwambocos
提出日時 2019-05-05 14:26:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 436 ms / 2,000 ms
コード長 520 bytes
コンパイル時間 1,775 ms
コンパイル使用メモリ 165,644 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-24 02:35:38
合計ジャッジ時間 5,544 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N, P;
	in >> N >> P;

	LL ans;
	if (P == 1) ans = 1;
	else
	{
		ans = N - 1;
		for (LL i = N / 2 + 1; i <= N; ++i)
		{
			bool flag = true;
			for (LL j = 2; j * j <= i; ++j)
			{
				if (i % j == 0)
				{
					flag = false;
					break;
				}
			}
			if (flag)
			{
				--ans;
				if (i == P)
				{
					ans = 1;
					break;
				}
			}
		}
	}

	out << ans << std::endl;
}
0