From 3c4d885ba7fd25731c030813888b6e3285ed7c2a Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Fri, 15 Jan 2021 13:45:26 +0100 Subject: problem 206 in c --- c/206-concealed_square.c | 41 +++++++++++++++++++++++++++++++++++++++++ python/206-concealed_square.py | 18 ------------------ 2 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 c/206-concealed_square.c delete mode 100644 python/206-concealed_square.py diff --git a/c/206-concealed_square.c b/c/206-concealed_square.c new file mode 100644 index 0000000..4b94486 --- /dev/null +++ b/c/206-concealed_square.c @@ -0,0 +1,41 @@ +/* +* Concealed Square +* Problem 206 +* +* Find the unique positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0, where each “_” is a single digit. +*/ + +#include +#include +#include + +typedef long long unsigned int t_llu; + +int main(void) +{ + t_llu n = (t_llu)floor(sqrt(1020304050607080900)) - 1000; + + while (true) + { + t_llu s = n * n; + + if ((s % 10llu) / 1llu == 0 && + (s % 1000llu) / 100llu == 9 && + (s % 100000llu) / 10000llu == 8 && + (s % 10000000llu) / 1000000llu == 7 && + (s % 1000000000llu) / 100000000llu == 6 && + (s % 100000000000llu) / 10000000000llu == 5 && + (s % 10000000000000llu) / 1000000000000llu == 4 && + (s % 1000000000000000llu) / 100000000000000llu == 3 && + (s % 100000000000000000llu) / 10000000000000000llu == 2 && + (s % 10000000000000000000llu) / 1000000000000000000llu == 1) + { + printf("%llu\n", n); + printf("%llu\n", s); + break; + } + n++; + } + + return 0; +} diff --git a/python/206-concealed_square.py b/python/206-concealed_square.py deleted file mode 100644 index e9d84ea..0000000 --- a/python/206-concealed_square.py +++ /dev/null @@ -1,18 +0,0 @@ -# ### -#Concealed Square -# -# Problem 206 -# Find the unique positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0, -# where each “_” is a single digit. -# ### - - -import math -from itertools import count - - -for n in count(int(math.sqrt(1020304050607080900)) - 1): - s = str(n * n) - if s[0] == "1" and s[2] == "2" and s[4] == "3" and s[6] == "4" and s[8] == "5" and s[10] == "6" and s[12] == "7" and s[14] == "8" and s[16] == "9" and s[18] == "0": - print(">>>", n) - break -- cgit