CLASS2を合格しました.
やはりWHITE HARD譜面が苦手です.
大学基礎数学を復習するために,以下の本を購入しました.
スバラシク実力がつくと評判の大学基礎数学キャンパス・ゼミ―大学の数学がこんなに分かる!単位なんて楽に取れる!
初めから学べると評判の大学基礎数学線形代数キャンパス・ゼミ (高校数学から大学数学へ!スムーズに実力UP!)
Problem 20:Factorial digit sum
n! means n × (n − 1) × ... × 3 × 2 × 1For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.Find the sum of the digits in the number 100!
import math strNum = str(math.factorial(100)) sum = 0 for i in strNum: sum += int(i) print(sum)
Problem 19:Counting Sundays
You are given the following information, but you may prefer to do some research for yourself.1 Jan 1900 was a Monday.
Thirty days has September,
April, June and November.
All the rest have thirty-one,
Saving February alone,
Which has twenty-eight, rain or shine.
And on leap years, twenty-nine.
A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
def zeller(year, month, day): if(month < 3): year -= 1 month += 12 return (year + year // 4 - year // 100 + year // 400 + (13 * month + 8 ) // 5 + day) % 7 count = 0 for i in range(1901, 2001): for j in range(1, 13): if zeller(i, j, 1) == 0: count += 1 print(count)
Problem 18:Maximum path sum I
By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23.3
7 4
2 4 6
8 5 9 3That is, 3 + 7 + 4 + 9 = 23.
Find the maximum total from top to bottom of the triangle below:
75
95 64
17 47 82
18 35 87 10
20 04 82 47 65
19 01 23 75 03 34
88 02 77 73 07 63 67
99 65 04 28 06 16 70 92
41 41 26 56 83 40 80 70 33
41 48 72 33 47 32 37 16 94 29
53 71 44 65 25 43 91 52 97 51 14
70 11 33 28 77 73 17 78 39 68 17 57
91 71 52 38 17 14 91 43 58 50 27 29 48
63 66 04 68 89 53 67 30 73 16 69 87 40 31
04 62 98 27 23 09 70 98 73 93 38 53 60 04 23
f = open("pe18.txt", "r") array = [] for line in f: text = line.replace('\n', '') text = text.replace('\r', '') text = text.split() temp = [int(i) for i in text] array.append(temp) f.close() # 初期設定 l = len(array) result = [0] * l for i in range(l - 1)[::-1]: for j in range(i + 1): temp = array[i + 1][j] if array[i + 1][j] > array[i + 1][j + 1] else array[i + 1][j + 1] array[i][j] += temp print(array[0][0])
75 95 64 17 47 82 18 35 87 10 20 04 82 47 65 19 01 23 75 03 34 88 02 77 73 07 63 67 99 65 04 28 06 16 70 92 41 41 26 56 83 40 80 70 33 41 48 72 33 47 32 37 16 94 29 53 71 44 65 25 43 91 52 97 51 14 70 11 33 28 77 73 17 78 39 68 17 57 91 71 52 38 17 14 91 43 58 50 27 29 48 63 66 04 68 89 53 67 30 73 16 69 87 40 31 04 62 98 27 23 09 70 98 73 93 38 53 60 04 23
Problem 17:Number letter counts
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
figure = { 0:"", 1:"one", 2:"two", 3:"three", 4:"four", 5:"five", 6:"six", 7:"seven", 8:"eight", 9:"nine", 10:"ten", 11:"eleven", 12:"twelve", 13:"thirteen", 14:"fourteen", 15:"fifteen", 16:"sixteen", 17:"seventeen", 18:"eighteen", 19:"nineteen", 20:"twenty", 30:"thirty", 40:"forty", 50:"fifty", 60:"sixty", 70:"seventy", 80:"eighty", 90:"ninety", 100:"hundred", 1000:"onethousand"} def num2wordLen(num): l = 0 # 1000の処理 if num == 1000: l += len(figure[1000]) return l # 100〜999の処理 q100 = num // 100 r100 = num % 100 if(q100 > 0): l += (len(figure[100]) + len(figure[q100])) # and処理 if(r100 != 0): l += 3 # 1〜99の処理 if(r100 < 20): l += len(figure[r100]) else: q10 = r100 // 10 r10 = r100 % 10 l += (len(figure[q10 * 10]) + len(figure[r10])) return l count = 0 for i in range(1, 1001): count += num2wordLen(i) print(count)
Problem 16:Power digit sum
2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.What is the sum of the digits of the number 2^1000?
strNum = str(2 ** 1000) sum = 0 for i in strNum: sum += int(i) print(sum)