結果
問題 | No.811 約数の個数の最大化 |
ユーザー |
![]() |
提出日時 | 2019-04-12 21:33:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 27 ms / 2,000 ms |
コード長 | 6,909 bytes |
コンパイル時間 | 1,218 ms |
コンパイル使用メモリ | 120,888 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-14 17:23:33 |
合計ジャッジ時間 | 1,982 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
// IO#include <cstdio>#include <iomanip>#include <ios>#include <iostream>// algorithm#include <algorithm>#include <cmath>#include <numeric>// container#include <vector>#include <string>#include <tuple>#include <set>#include <map>#include <unordered_map>#include <stack>#include <queue>#include <deque>// others#include <random>#include <limits>#include <functional>#include <ctime>#include <cassert>// type aliasusing lint = long long;using ldouble = long double;template <class T>using greater_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T>>;/* ----- class ----- */template <class Cost = int>struct Edge {int from, to;Cost cost;Edge(int from = -1, int to = -1, Cost cost = 1): from(from), to(to), cost(cost){};bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }};template <class Cost = int>using Edges = std::vector<Edge<Cost>>;template <class Cost = int>class Graph {public:int size;std::vector<std::vector<Edge<Cost>>> path;explicit Graph(int N = 0) : size(N), path(size) {}void span(int from, int to, Cost cost = 1) {path[from].push_back(Edge<Cost>(from, to, cost));}std::vector<Edge<Cost>>& operator[](int v) { return path[v]; }};/* ----- Output Functions for Debugging ----- */template <class T>std::ostream& operator<<(std::ostream& os, std::vector<T> v);template <class T>std::ostream& operator<<(std::ostream& os, std::set<T> v);template <class L, class R>std::ostream& operator<<(std::ostream& os, std::pair<L, R> p);template <class K, class T>std::ostream& operator<<(std::ostream& os, std::map<K, T> v);template <class T>std::ostream& operator<<(std::ostream& os, std::stack<T> s);template <class T>std::ostream& operator<<(std::ostream& os, std::queue<T> q);template <class T>std::ostream& operator<<(std::ostream& os, std::priority_queue<T> q);template <class T>std::ostream& operator<<(std::ostream& os, std::priority_queue<T, std::vector<T>, std::greater<T>> q);template <class T>std::ostream& operator<<(std::ostream& os, Edge<T> e);template <class T>std::ostream& operator<<(std::ostream& os, std::vector<T> v) {os << "[";for (auto vv : v) os << vv << ",";return os << "]";}template <class T>std::ostream& operator<<(std::ostream& os, std::set<T> v) {os << "{";for (auto vv : v) os << vv << ",";return os << "}";}template <class L, class R>std::ostream& operator<<(std::ostream& os, std::pair<L, R> p) {return os << "(" << p.first << "," << p.second << ")";}template <class K, class T>std::ostream& operator<<(std::ostream& os, std::map<K, T> v) {os << "{";for (auto vv : v) os << vv << ",";return os << "}";}template <class T>std::ostream& operator<<(std::ostream& os, std::stack<T> s) {os << "[";while (!s.empty()) {os << s.top() << ",";s.pop();}return os << "]";}template <class T>std::ostream& operator<<(std::ostream& os, std::queue<T> q) {os << "[";while (!q.empty()) {os << q.front() << ",";q.pop();}return os << "]";}template <class T>std::ostream& operator<<(std::ostream& os, std::priority_queue<T> q) {os << "{";while (!q.empty()) {os << q.top() << ",";q.pop();}return os << "}";}template <class T>std::ostream& operator<<(std::ostream& os, std::priority_queue<T, std::vector<T>, std::greater<T>> q) {os << "{";while (!q.empty()) {os << q.top() << ",";q.pop();}return os << "}";}template <class T>std::ostream& operator<<(std::ostream& os, Edge<T> e) {return os << "(" << e.from << "->" << e.to << ":" << e.cost << ")";}/* ----- Short Functions ----- */template <class T>inline T sq(T a) { return a * a; }template <class T>inline T iceil(T n, T d) { return (n + d - 1) / d; }template <class T>T gcd(T a, T b) {while (b > 0) {a %= b;std::swap(a, b);}return a;}template <class T, class U>T ipow(T b, U n) {T ret = 1;while (n > 0) {if (n & 1) ret *= b;n >>= 1;b *= b;}return ret;}// 0-indexedtemplate <class T, class U>inline T kthbit(T a, U k) { return (a >> k) & 1; }template <class T, class U>inline T mask(T a, U k) { return a & ((1 << k) - 1); }template <class T>std::map<T, int> compress(std::vector<T>& v) {std::sort(v.begin(), v.end());v.erase(std::unique(v.begin(), v.end()), v.end());std::map<T, int> rev;for (int i = 0; i < v.size(); ++i) rev[v[i]] = i;return rev;}template <class T>T Vec(T v) { return v; }template <class T, class... Ts>auto Vec(size_t l, Ts... ts) {return std::vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));}/* ----- Constants ----- */// const int INF = std::numeric_limits<int>::max() / 3;// const ll INF = std::numeric_limits<ll>::max() / 3;// const ld PI = acos(-1);// const ld EPS = 1e-10;// std::mt19937 mt(int(std::time(nullptr)));class Prime {using lint = long long;public:int MAX_V;std::vector<int> primes;std::vector<bool> isp;explicit Prime(int N) : MAX_V(N) {isp.assign(MAX_V + 1, true);isp[0] = isp[1] = false;for (int i = 2; i * i <= MAX_V; ++i) {if (isp[i]) {for (int j = i; i * j <= MAX_V; ++j) {isp[i * j] = false;}}}for (int p = 2; p <= MAX_V; ++p) {if (isp[p]) primes.push_back(p);}}bool isprime(lint N) const {if (N <= MAX_V) return isp[N];for (lint p : primes) {if (p * p > N) break;if (N % p == 0) return false;}return true;}std::vector<std::pair<lint, int>> factorization(lint N) const {std::vector<std::pair<lint, int>> ret;for (lint p : primes) {if (p * p > N) break;if (N % p != 0) continue;int cnt = 0;while (N % p == 0) {N /= p;++cnt;}ret.emplace_back(p, cnt);}if (N > 1) ret.emplace_back(N, 1);return ret;}};const Prime P(100010);int main() {int N, K;std::cin >> N >> K;int ans = 0, maxf = 0;for (int n = 1; n < N; ++n) {int g = gcd(N, n);auto facts = P.factorization(g);int f = 0;for (auto p : facts) f += p.second;if (f < K) continue;facts = P.factorization(n);f = 1;for (auto p : facts) f *= (p.second + 1);if (maxf < f) {ans = n;maxf = f;}}std::cout << ans << std::endl;return 0;}