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的更多相关文章

  1. (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 ...

  2. 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 ...

  3. CF28D Don't fear, DravDe is kind 背包

    题目传送门:http://codeforces.com/problemset/problem/28/D 题意:给你$N$个物品,每个物品有其价格$P_i$,之前必须要买的物品价格和$L_i$,之后必须 ...

  4. Time Limit Exceeded 求逆序对数。

    /** 题目:Time Limit Exceeded 链接:https://oj.ejq.me/problem/28 题意:求逆序对数. 思路:树状数组求逆序对数.维护前面有多少个<=当前数的数 ...

  5. PID28 [Stupid]愚蠢的宠物

    题链:https://www.rqnoj.cn/problem/28 题目描述 背景 大家都知道,sheep有两只可爱的宠物(一只叫神牛,一只叫神菜).有一天,sheep带着两只宠物到狗狗家时,这两只 ...

  6. Levmar:Levenberg-Marquardt非线性最小二乘算法

    Levmar:Levenberg-Marquardt非线性最小二乘算法 eryar@163.com Abstract. Levmar is GPL native ANSI C implementati ...

  7. 【VS开发】设备控制台 (DevCon.exe) 示例

    设备控制台 (DevCon.exe) 示例 本部分提供以下设备控制台 (DevCon.exe) 命令的示例: DevCon HwIDs 示例 1:查找所有硬件 ID 示例 2:使用模式查找硬件 ID ...

  8. B. pSort

    题目链接: http://codeforces.com/problemset/problem/28/B 题意: 给一个n,原本有个1到n按顺序排列的序列,给一个序列问,在给一个数组,表示这个位置的数可 ...

  9. 《DSP using MATLAB》Problem 5.28

    昨晚手机在看X信的时候突然黑屏,开机重启都没反应,今天维修师傅说使用时间太长了,还是买个新的吧,心疼银子啊! 这里只放前两个小题的图. 代码: 1. %% ++++++++++++++++++++++ ...

随机推荐

  1. 操作系统的时区设置会影响数据库查询SYSDATE和SYSTIMESTAMP的值

    SYSDATE和SYSTIMESTAMP的值并不受数据库參数DBTIMEZONE的影响,操作系统时区的环境变量(如TZ)会影响它们的输入,由于SYSDATE和SYSTIMESTAMP实际是调用操作系统 ...

  2. ios16--自定义控件1

    k控制器: // // XMGViewController.h #import <UIKit/UIKit.h> @interface XMGViewController : UIViewC ...

  3. 2017iOS开发最新的打包测试步骤(亲测)

    最近也是忙着修改项目,今天把最近遇到的问题和知识给大家分享一下. 有时候我们需要将我们的项目发给测试组进行bug测试,这时候我们就需要把自己的项目打包,生成一个二维码或者链接的形式,给测试组,接下来就 ...

  4. Head First 设计模式 —— 单例模式(Singleton)

    单例模式简要定义:单例模式确保一个类只有一个实例,并提供一个全局访问点. 1. 如何保证一个类只有一个实例,且这个实例易于被访问? lazy evaluation:在用到的时候才创建对象. 全局变量: ...

  5. Scala 返回多个值

    class A{ var c var d def return={ (c,d,"soyo") //以元组形式返回 }}调用: val s=new A var(a1,a2,a3)=s ...

  6. eclipse.ini启动参数配置的解析及方法

    原文地址 - http://www.uzzf.com/news/18444.html 1.先了解下JVM内存管理机制,JVM内存分为堆内存和非堆内存 2.JVM内存限制 首先JVM内存限制于实际的最大 ...

  7. php安全过滤类

    /*ansic码-Url码表: http://www.w3school.com.cn/tags/html_ref_urlencode.html ---------------------------- ...

  8. 过河 2005年NOIP全国联赛提高组(离散化+dp)

    1105 过河 2005年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond       题目描述 Description 在河上有一 ...

  9. printf的字符型

    参  数 说  明 %s 按实际宽度输出一个字符串 %ms m指定宽度(不足时左补空格,大于时按实际宽度输出) %-ms 左对齐,不足时右补空格 %m.ns 输出占m个字符位置,其中字符数最多n个,左 ...

  10. UNIX环境高级编程--6

    系统数据文件和信息    数据文件都是ASCII文本文件,并且使用标准I/O库读这些文件,例如口令文件/etc/passwd和组文件/etc/group就是经常被多个程序频繁使用的两个文件.    口 ...