--- /dev/null
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The 5-digit number, $16807=7^5$, is also a fifth power. Similarly, the 9-digit number, $134217728=8^9$, is a ninth power.\n",
+ "\n",
+ "How many _n_-digit positive integers exist which are also an *n*th power?\n",
+ "\n",
+ "$(\\log_{10} x) + 1 = n ; x = y ^ n$\n",
+ "\n",
+ "$log_y x = n = (\\log_{10} x) + 1$\n",
+ "\n",
+ "Possibly valid if $ log_y x \\le n = (\\log_{10} x) + 1$\n",
+ "\n",
+ "Possibly valid if $\\log_{10} y^n \\le n + 1$\n",
+ "\n",
+ "$n \\log_{10} y \\le n + 1$\n",
+ "\n",
+ "$\\log_{10} y \\le \\frac{n + 1}{n}$\n",
+ "\n",
+ "$y < 10$ as $10^n$ has $n+1$ digits.\n",
+ "\n",
+ "$y^n$ has $\\left \\lfloor \\log_{10} y^n \\right \\rfloor + 1 = \\left \\lfloor n \\log_{10} y \\right \\rfloor + 1$ digits.\n",
+ "\n",
+ "$\\left \\lfloor n \\log_{10} y \\right \\rfloor + 1 = n$\n",
+ "\n",
+ "$n \\left \\lfloor \\log_{10} y \\right \\rfloor = n - 1$\n",
+ "\n",
+ "$\\left \\lfloor \\log_{10} y \\right \\rfloor = \\frac{n - 1}{n}$\n",
+ "\n",
+ "$\\left \\lfloor \\log_{10} y \\right \\rfloor = 1 - \\frac{1}{n}$\n",
+ "\n",
+ "$\\frac{1}{n} = 1 - \\left \\lfloor \\log_{10} y \\right \\rfloor$\n",
+ "\n",
+ "${n} = \\frac{1}{1 - \\left \\lfloor \\log_{10} y \\right \\rfloor}$\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "$ n \\log_{10} y + 1 < n$\n",
+ "\n",
+ "$n \\log_{10} y< n - 1$\n",
+ "\n",
+ "$ \\log_{10} y < \\frac{n - 1}{n}$\n",
+ "\n",
+ "$\\log_{10} y < 1 - \\frac{1}{n}$\n",
+ "\n",
+ "$\\frac{1}{n} > 1 - \\log_{10} y $\n",
+ "\n",
+ "${n} < \\frac{1}{1 - \\log_{10} y}$\n",
+ "\n",
+ "${n} = \\left \\lfloor \\frac{1}{1 - \\log_{10} y} \\right \\rfloor$\n",
+ "\n",
+ "| y | n | $y^n$ |\n",
+ "|-----|\n",
+ "| 1 | 1 | 1 |\n",
+ "| 2 | 1 | 2 |\n",
+ "| 3 | 1 | 3 |\n",
+ "| 4 | 1 | 4 |\n",
+ "| 4 | 2 | 16 |\n",
+ "| 5 | 1 | 5 |\n",
+ "| 5 | 2 | 25 |\n",
+ "| 5 | 3 | 125 |\n",
+ "| 6 | 1 | 6 |\n",
+ "| 6 | 2 | 36 |\n",
+ "| 6 | 3 | 216 |\n",
+ "| 6 | 4 | 1296 |\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "1, 1\n",
+ "2, 1\n",
+ "3, 1\n",
+ "4, 2\n",
+ "5, 3\n",
+ "6, 4\n",
+ "7, 6\n",
+ "8, 10\n",
+ "9, 21\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "1..9"
+ ]
+ },
+ "execution_count": 26,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "(1..9).each do |y|\n",
+ " puts \"#{y}, #{(1 / (1 - Math.log(y, 10))).floor}\"\n",
+ "end"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "49"
+ ]
+ },
+ "execution_count": 25,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "(1..9).map {|y| (1 / (1 - Math.log(y, 10))).floor}.sum"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Ruby 2.4.0",
+ "language": "ruby",
+ "name": "ruby"
+ },
+ "language_info": {
+ "file_extension": ".rb",
+ "mimetype": "application/x-ruby",
+ "name": "ruby",
+ "version": "2.4.0"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}