Submission #72598350
Source Code Expand
Copy
#include <stdio.h>int main(void) {int n;int soinsu[64], n_soinsu[64];int soinsu_cnt = 0;int i, m;if (scanf("%d", &n) != 1) return 1;/* 素因数分解をする */for (i = 2; i * i <= n; i++) {if (n % i == 0) {soinsu[soinsu_cnt] = i;n_soinsu[soinsu_cnt] = 0;while (n % i == 0) {n_soinsu[soinsu_cnt]++;n /= i;}soinsu_cnt++;}}if (n > 1) {
#include <stdio.h>
int main(void) {
int n;
int soinsu[64], n_soinsu[64];
int soinsu_cnt = 0;
int i, m;
if (scanf("%d", &n) != 1) return 1;
/* 素因数分解をする */
for (i = 2; i * i <= n; i++) {
if (n % i == 0) {
soinsu[soinsu_cnt] = i;
n_soinsu[soinsu_cnt] = 0;
while (n % i == 0) {
n_soinsu[soinsu_cnt]++;
n /= i;
}
soinsu_cnt++;
}
}
if (n > 1) {
soinsu[soinsu_cnt] = n;
n_soinsu[soinsu_cnt] = 1;
soinsu_cnt++;
}
/* 下から素因数を削っていく */
for (m = 2; ; m++) {
int all_clear = 1;
int oh = 1, oh_min = 0, oh_max = 0;
int cur = m;
for (i = 0; i < soinsu_cnt; i++) {
while (n_soinsu[i] > 0 && cur % soinsu[i] == 0) {
n_soinsu[i]--;
cur /= soinsu[i];
}
all_clear = all_clear && n_soinsu[i] == 0;
oh = oh && n_soinsu[i] <= 1;
if (n_soinsu[i] == 1) {
if (oh_min == 0) oh_min = soinsu[i];
oh_max = soinsu[i];
}
}
if (all_clear) {
printf("%d\n", m);
return 0;
}
if (oh && m < oh_min) {
printf("%d\n", oh_max);
return 0;
}
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | factorial - 階乗 (Factorial) |
| User | mikecat |
| Language | C23 (GCC 14.2.0) |
| Score | 100 |
| Code Size | 1105 Byte |
| Status | AC |
| Exec Time | 0 ms |
| Memory | 1740 KiB |
Judge Result
| Set Name | Set01 | Set02 | Set03 | Set04 | Set05 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 20 / 20 | 20 / 20 | 20 / 20 | 20 / 20 | 20 / 20 | ||||||||||
| Status |
|
|
|
|
|
| Set Name | Test Cases |
|---|---|
| Set01 | 01 |
| Set02 | 02 |
| Set03 | 03 |
| Set04 | 04 |
| Set05 | 05 |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01 | AC | 0 ms | 1688 KiB |
| 02 | AC | 0 ms | 1740 KiB |
| 03 | AC | 0 ms | 1688 KiB |
| 04 | AC | 0 ms | 1728 KiB |
| 05 | AC | 0 ms | 1656 KiB |