题意:给出一个 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. Android 自己定义TextView 实现文本间距

    转载请标明出处: http://blog.csdn.net/u011974987/article/details/50845269: Android系统中TextView默认显示中文时会比較紧凑.不是 ...

  2. HDU 4527

    搞了好久,发现自己是想法没错的,错在输入,必须是while(){} #include <iostream> #include <cstdio> #include <alg ...

  3. java中byte类型

    http://www.cnblogs.com/Robotke1/archive/2013/05/25/3099309.html ------------------------------------ ...

  4. java构造函数重载this(true)

    看storm的代码的时候,发现这样一句java代码, 很是不理解 google之后,发现原来是java语法中,构造函数重载,this()调用的其实就是 构造函数.This is constructor ...

  5. ASP怎样检測某目录是否存在,不存在则自己主动创建

    ASP怎样检測某目录是否存在,不存在则自己主动创建 folder=server.mappath("/imagess")  Set fso = CreateObject(" ...

  6. 64bit Centos6.4搭建hadoop-2.5.1

    64bit Centos6.4搭建hadoop-2.5.1 1.分布式环境搭建 採用4台安装Linux环境的机器来构建一个小规模的分布式集群. 当中有一台机器是Master节点,即名称节点,另外三台是 ...

  7. HTTP详解工作原理

    1. HTTP简介 HTTP协议(HyperText Transfer Protocol,超文本传输协议)是用于从WWW服务器传输超文本到本地浏览器的传送协议.它可以使浏览器更加高效,使网络传输减少. ...

  8. hdu 1698 Just a Hook 基本线段树

    使用线段树更新每段区间的奖(1,2,3),最后在统计整段区间的数和,基本线段树,果断1A啊 #include<iostream> #include<stdio.h> using ...

  9. luogu1403 约数研究

    题目大意:给出n,求1~n所有数的约数个数的和. 将“1~n所有数的约数”的模板中的factor[i*j].push_back(i)改为FactorCnt[i*j]++,最后再求一次和即可. #inc ...

  10. identity in sql server 批量插入history

    https://stackoverflow.com/questions/1920558/what-is-the-difference-between-scope-identity-identity-i ...