题意:给出一个 1001 × 1001 的矩阵,寻找每一圈四个顶点,并求出所有顶点的和

思路:只需要找到右上顶点数字的规律,然后每一圈四个顶点构成了一个等差数列,求个和即可


/*************************************************************************
> File Name: euler028.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年05月23日 星期二 16时50分16秒
************************************************************************/ #include<bits/stdc++.h>
using namespace std; #define ll long long int main(){
ll sum = 1;
int n = ( 1001 + 1 ) / 2;
for(int i = 2 ; i <= n ; i++){
sum += (ll)4*(2*i-1)*(2*i-1) - 12*(i-1);
}
printf("sum = %lld\n",sum);
return 0;
}

Project Euler 28 Number spiral diagonals的更多相关文章

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

  2. (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. Python练习题 045:Project Euler 017:数字英文表达的字符数累加

    本题来自 Project Euler 第17题:https://projecteuler.net/problem=17 ''' Project Euler 17: Number letter coun ...

  4. Python练习题 040:Project Euler 012:有超过500个因子的三角形数

    本题来自 Project Euler 第12题:https://projecteuler.net/problem=12 # Project Euler: Problem 12: Highly divi ...

  5. Python练习题 039:Project Euler 011:网格中4个数字的最大乘积

    本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...

  6. [project euler] program 4

    上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...

  7. Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.

    In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...

  8. 【Project Euler 8】Largest product in a series

    题目要求是: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × ...

  9. Python练习题 048:Project Euler 021:10000以内所有亲和数之和

    本题来自 Project Euler 第21题:https://projecteuler.net/problem=21 ''' Project Euler: Problem 21: Amicable ...

随机推荐

  1. HDU 1576 A/B(扩展欧几里德变形)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 Problem Description 要求(A/B)%9973,但因为A非常大,我们仅仅给出n ...

  2. POJ 1442 Black Box(优先队列)

    题目地址:POJ 1442 这题是用了两个优先队列,当中一个是较大优先.还有一个是较小优先. 让较大优先的队列保持k个.每次输出较大优先队列的队头. 每次取出一个数之后,都要先进行推断,假设这个数比較 ...

  3. setResult详解

    startActivityForResult与startActivity的不同之处在于:1.startActivity( ) 仅仅是跳转到目标页面,若是想跳回当前页面,则必须再使用一次startAct ...

  4. 【Codeforces 258A】 Game With Sticks

    [题目链接] http://codeforces.com/contest/451/problem/A [算法] 若n和m中的最小值是奇数,则先手胜,否则后手胜 [代码] #include<bit ...

  5. reportlab使用示例:文字和图片

    Python的reportlab专门将数据使用生成PDF中的图形和文档功能, 下载ReportLab https://pypi.python.org/simple/reportlab/ http:// ...

  6. Qt5.9 WebEngine 概述

    Qt WebEngine模块提供了一个web浏览器, 在不使用本地浏览器的情况下, 它可以很容易地把Web内容嵌入到Qt应用程序中. Qt WebEngine为渲染HTML, XHTML和SVG文档, ...

  7. Scrapy中的核心工作流程以及POST请求

    五大核心组件工作流程 post请求发送 递归爬取 五大核心组件工作流程 引擎(Scrapy)用来处理整个系统的数据流处理, 触发事务(框架核心) 调度器(Scheduler)用来接受引擎发过来的请求, ...

  8. WRAR下载及注册

    下载过程: 1.打开winrar官网:https://www.win-rar.com 2.点击下载winrar按钮,如上图所示 3.进入下一页面,点击下载按钮即可完成下载过程 注册过程:https:/ ...

  9. Unity3d 刚体

    using UnityEngine; using System.Collections; public class rigidbody_ : MonoBehaviour { private Rigid ...

  10. 以SqlHelper为例论面向对象中封装的使用(续)

    上文以SqlHelper为例说明了面向对象中封装的好处,但是上文只是简单封装,考虑下面代码的情况: public static Activate GetByCode(string code) { Li ...