結果

問題 No.811 約数の個数の最大化
ユーザー matsukin1111matsukin1111
提出日時 2019-04-12 21:59:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 1,805 bytes
コンパイル時間 847 ms
コンパイル使用メモリ 96,708 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 20:14:11
合計ジャッジ時間 1,755 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 12 ms
4,352 KB
testcase_10 AC 3 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 78 ms
4,352 KB
testcase_14 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:117:17: 警告: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
  117 |         cout << ans << endl;
      |                 ^~~
main.cpp:104:13: 備考: ‘ans’ はここで定義されています
  104 |         int ans;
      |             ^~~

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };

vector<int>dev;
vector<int>prdev;

bool prime(ll n) {
	if (n == 1) {
		return false;
	}
	for (ll i = 2; i*i <= n; i++) {
		if (n%i == 0) {
			return false;
		}
	}
	return true;
}


void devisor(ll n) {
	for (ll i = 1; i*i <= n; i++) {
		if (n%i == 0) {
			if (i == n / i) {
				dev.push_back(i);
			}
			else {
				dev.push_back(i);
				dev.push_back(n / i);
			}
		}
	}
}

int po(int x, int y) {
	int ret = 1;
	rep(i, 0, y) {
		ret *= x;
	}
	return ret;
}

int dp[101010];

int main() {
	int n, k;
	cin >> n >> k;
	devisor(n);

	fore(i, dev) {
		if (prime(i)) {
			prdev.pb(i);
		}
	}

	fore(i, prdev) {
		int cnt = 0;
		int temp = n;
		while (temp > 0) {
			if (temp % i == 0)cnt++;
			else break;
			temp /= i;
		}
		for (int k = 1; k <= cnt; k++) {
			int c = po(i, k);
			for (int j = c; j < n; j += c) {
				dp[j]++;
			}
		}
	}

	int sz = -1;
	int ans;
	rep(i, 1, n) {
		if (dp[i] >= k) {
			dev.clear();
			devisor(i);
			int p = dev.size();
			if (p > sz) {
				ans = i;
				sz = dev.size();
			}
		}
	}

	cout << ans << endl;


	return 0;
}
0