Project Euler 28 Number spiral diagonals
题意:给出一个 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的更多相关文章
- 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 ...
- (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 ...
- Python练习题 045:Project Euler 017:数字英文表达的字符数累加
本题来自 Project Euler 第17题:https://projecteuler.net/problem=17 ''' Project Euler 17: Number letter coun ...
- Python练习题 040:Project Euler 012:有超过500个因子的三角形数
本题来自 Project Euler 第12题:https://projecteuler.net/problem=12 # Project Euler: Problem 12: Highly divi ...
- Python练习题 039:Project Euler 011:网格中4个数字的最大乘积
本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...
- [project euler] program 4
上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...
- 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 ...
- 【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 × ...
- Python练习题 048:Project Euler 021:10000以内所有亲和数之和
本题来自 Project Euler 第21题:https://projecteuler.net/problem=21 ''' Project Euler: Problem 21: Amicable ...
随机推荐
- Ajax跨域访问的问题
在本机调试Ajax的时候如果服务器在另外的网址,Chrome会出现 Origin is not allowed by Access-Control-Allow-Origin. 解决方案是禁用Chro ...
- IT人才异军突起 有招网引领业界精英
随着网络时代的到来,IT人才也在不断的增长.当然,不仅IT行业对IT人才需求旺盛.部分传统企业为打造互联网时代下的企业,也在紧锣密鼓的招聘IT人才.据统计.眼下我国各地对IT人才的需求已经占领总体人才 ...
- AC自己主动机模板(数组实现版)
BY 九野 做了一道题,用我的那种写法华丽丽的超时了.,无奈学一学数组实现的 #include<stdio.h> #include<string.h> #include< ...
- C# - Generics
Generics were added to version 2.0 of the C# language and the common language runtime (CLR). Generic ...
- HDU 1576 A/B(扩展欧几里德变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 Problem Description 要求(A/B)%9973,但因为A非常大,我们仅仅给出n ...
- php学习随记3
<? php #正則表達式 #就是一种描写叙述字符串结构的语法规则 #是一个特定的格式化模式 #1. 行定位符 /* 1) ^行首 2)$行尾 tm eqaul Tomorrow Moon ^t ...
- android-PullRefreshLayout使用
类似与谷歌的SwipeRefreshLayout.但比SwipeRefreshLayout美丽. 执行效果: 使用说明: 用法和SwipeRefreshLayout几乎相同. 在xml中: 1 2 3 ...
- 2016.04.19,英语,《Vocabulary Builder》Unit 16
top, comes from topos, the Greek word for 'place'. ectopic: [ek'tɑːpɪk] adj. [医]异位的,异常的 topical: ['t ...
- Linux下开启vim高亮
默认是不高亮的. [root@local ~]# vi ~/.vimrc 没有则新建这个文件. 或者修改 [root@local vim74]# vi /etc/vimrc 添加一行. syntax ...
- SUSE glibc升级为2.18过程记录
先验知识:1.运行时,动态库的装载依赖于ld-linux.so.6的实现,它查找共享库的顺序如下:(1)ld-linux.so.6在可执行的目标文件中被指定,可用readelf命令查看(2)ld-li ...