Problem 28
Problem 28
https://projecteuler.net/problem=28
Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:
从1开始,顺时针旋螺转,可得一个5*5的螺旋如下:
21 22 23 24 25
20 7 8 9 10
19 6 1 2 11
18 5 4 3 12
17 16 15 14 13
It can be verified that the sum of the numbers on the diagonals is 101.
对角线上的数字(粗体)之和等于101。
What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way?
一个类似的1001*1001的螺旋的对角线上的数字之和为多少?
from math import pow row = 1001
matrix = row * row
tot = [1]
spiral = [i for i in range(2, matrix+1)]
spiral = spiral[::-1] # 倒序排列螺旋 interval = 1
count = 0
while True:
try:
for i in range(interval): # 每隔interval个数字,加入一个数字至tot列表
spiral.pop()
tot.append(spiral.pop())
count += 1
if count == 4: # 每加入四个数字,interval加二
interval += 2
count = 0
except:
break print(sum(tot), tot)
Problem 28的更多相关文章
- (Problem 28)Number spiral diagonals
Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is forme ...
- Project Euler:Problem 28 Number spiral diagonals
Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is forme ...
- CF28D Don't fear, DravDe is kind 背包
题目传送门:http://codeforces.com/problemset/problem/28/D 题意:给你$N$个物品,每个物品有其价格$P_i$,之前必须要买的物品价格和$L_i$,之后必须 ...
- Time Limit Exceeded 求逆序对数。
/** 题目:Time Limit Exceeded 链接:https://oj.ejq.me/problem/28 题意:求逆序对数. 思路:树状数组求逆序对数.维护前面有多少个<=当前数的数 ...
- PID28 [Stupid]愚蠢的宠物
题链:https://www.rqnoj.cn/problem/28 题目描述 背景 大家都知道,sheep有两只可爱的宠物(一只叫神牛,一只叫神菜).有一天,sheep带着两只宠物到狗狗家时,这两只 ...
- Levmar:Levenberg-Marquardt非线性最小二乘算法
Levmar:Levenberg-Marquardt非线性最小二乘算法 eryar@163.com Abstract. Levmar is GPL native ANSI C implementati ...
- 【VS开发】设备控制台 (DevCon.exe) 示例
设备控制台 (DevCon.exe) 示例 本部分提供以下设备控制台 (DevCon.exe) 命令的示例: DevCon HwIDs 示例 1:查找所有硬件 ID 示例 2:使用模式查找硬件 ID ...
- B. pSort
题目链接: http://codeforces.com/problemset/problem/28/B 题意: 给一个n,原本有个1到n按顺序排列的序列,给一个序列问,在给一个数组,表示这个位置的数可 ...
- 《DSP using MATLAB》Problem 5.28
昨晚手机在看X信的时候突然黑屏,开机重启都没反应,今天维修师傅说使用时间太长了,还是买个新的吧,心疼银子啊! 这里只放前两个小题的图. 代码: 1. %% ++++++++++++++++++++++ ...
随机推荐
- Index statistics collected bug
SQL运行引擎会从pg_stats.pg_class等相关系统字典表.视图获取生成最佳运行计划的数据,假设相关字典视图的数据不准确就没有办法生成良好的运行计划. 发现下面Bug一枚. 0. 插入数据之 ...
- Selenium-一个用于Web应用程序测试的工具
Selenium.pptx
- 【RAID在数据库存储上的应用 】
随着单块磁盘在数据安全.性能.容量上呈现出的局限,磁盘阵列(Redundant Arrays of Inexpensive/Independent Disks,RAID)出现了,RAID把多块独立的磁 ...
- Django-CKeditor使用笔记
1. 安装django-ckeditor $ pip install django-ckeditor 2. 在setting中,添加ckeditor , ckeditor_uploader 到INST ...
- selenium3 + python - autoit上传文件
一.环境准备: 1.可以autoit官网上下载,安装 http://www.autoitscript.com/site/ 2.AutoIt里面几个菜单功能介绍: SciTE Script Editor ...
- sigar的使用
与普通jar包不同,Sigar API还要依赖本地的库文件来进行工作,其中: Windows下Sigar.jar 依赖:sigar-amd64-winnt.dll 或 sigar-x86-winnt. ...
- IOS上微信在输入框弹出键盘后,页面不恢复,下方有留白,有弹窗弹出时页面内容感应区域错位
问题说明: ios中,键盘的弹起,页面会往上挪动,使输入框展示在页面中间,键盘隐藏页面会下挪恢复原状. 在微信移动端,ios页面不恢复,下方有留白. 收起键盘的瞬间,如果有弹窗弹出,此时时页面内容应区 ...
- BZOJ 3456 NTT图的计数 容斥
思路: RT 懒得写了 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm&g ...
- Laravel 5.4.36 session 生效问题
在测试过程中发现 如果方法有echo 等函数输出到PHP的输出缓存中 存在 sessionID 不会放到http的请求头中 下次请求也就拿不到sessionid问题 问题的原因 代码位置:publ ...
- iOS device is locked/unlocked (判断手机屏幕是否锁屏)
#import <notify.h> -(void)checkDeviceLockScreenState { int notify_token; notify_register_dispa ...