Submission #74758782
Source Code Expand
Copy
#include <stdio.h>int sousa(int x) {int res = 0;while (x > 0) {int d = x % 10;x /= 10;res += d * d;}return res;}char visited[114514];int main(void) {int N;if (scanf("%d", &N) != 1) return 1;while (N != 1) {if (visited[N]) {puts("No");return 0;}visited[N] = 1;N = sousa(N);}puts("Yes");return 0;}/*実験の結果、多分244までしかいかないPython 3.11.4 (tags/v3.11.4:d2340ef, Jun 7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> def sousa(x):... return sum([int(c) * int(c) for c in str(x)])...>>> sousa(2026)44>>> m = 0
#include <stdio.h>
int sousa(int x) {
int res = 0;
while (x > 0) {
int d = x % 10;
x /= 10;
res += d * d;
}
return res;
}
char visited[114514];
int main(void) {
int N;
if (scanf("%d", &N) != 1) return 1;
while (N != 1) {
if (visited[N]) {
puts("No");
return 0;
}
visited[N] = 1;
N = sousa(N);
}
puts("Yes");
return 0;
}
/*
実験の結果、多分244までしかいかない
Python 3.11.4 (tags/v3.11.4:d2340ef, Jun 7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def sousa(x):
... return sum([int(c) * int(c) for c in str(x)])
...
>>> sousa(2026)
44
>>> m = 0
>>> for i in range(1, 2026 + 1):
... v = i
... for _ in range(10000):
... v = sousa(v)
... m = max(v, m)
...
>>> m
244
>>>
*/
Submission Info
| Submission Time | |
|---|---|
| Task | B - Happy Number |
| User | mikecat |
| Language | C23 (GCC 14.2.0) |
| Score | 200 |
| Code Size | 866 Byte |
| Status | AC |
| Exec Time | 1 ms |
| Memory | 1676 KiB |
Judge Result
| Set Name | Sample | All | after_contest | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 200 / 200 | 0 / 0 | ||||||
| Status |
|
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt |
| after_contest | after_contest_01.txt, after_contest_02.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| after_contest_01.txt | AC | 0 ms | 1536 KiB |
| after_contest_02.txt | AC | 1 ms | 1564 KiB |
| sample_01.txt | AC | 0 ms | 1552 KiB |
| sample_02.txt | AC | 0 ms | 1500 KiB |
| sample_03.txt | AC | 0 ms | 1652 KiB |
| test_01.txt | AC | 0 ms | 1528 KiB |
| test_02.txt | AC | 0 ms | 1552 KiB |
| test_03.txt | AC | 0 ms | 1552 KiB |
| test_04.txt | AC | 0 ms | 1604 KiB |
| test_05.txt | AC | 0 ms | 1620 KiB |
| test_06.txt | AC | 0 ms | 1652 KiB |
| test_07.txt | AC | 0 ms | 1676 KiB |
| test_08.txt | AC | 0 ms | 1648 KiB |
| test_09.txt | AC | 0 ms | 1640 KiB |
| test_10.txt | AC | 0 ms | 1580 KiB |
| test_11.txt | AC | 0 ms | 1500 KiB |
| test_12.txt | AC | 0 ms | 1648 KiB |
| test_13.txt | AC | 0 ms | 1640 KiB |
| test_14.txt | AC | 0 ms | 1544 KiB |
| test_15.txt | AC | 0 ms | 1652 KiB |
| test_16.txt | AC | 0 ms | 1552 KiB |
| test_17.txt | AC | 0 ms | 1652 KiB |
| test_18.txt | AC | 0 ms | 1500 KiB |
| test_19.txt | AC | 0 ms | 1640 KiB |
| test_20.txt | AC | 0 ms | 1552 KiB |