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 ...
随机推荐
- 项目 cmdb(一)
Django之ModelForm组件 ModelForm a. class Meta: model, # 对应Mode ...
- 性能优化——mysql数据库
一 mysql经常使用命令 1. 打开日志 1) show global variables like "%genera%"; 2)set global general_log=o ...
- 在Map对象中获取属性,注意判断为空
在Map对象中获取属性,注意判断为空 public static void main(String[] args) { Map map = new HashMap(); Integer i = (In ...
- jQuery学习之开篇
吐槽 近期比較烦,对于一个前端白痴来说,工作方向突然转向前端这块着实让人蛋疼无比.前段时间简单的学习了下EasyUI,算是对其有一个简单的认知了吧.EasyUI的研究过程中发现,假设没有掌握JS.JQ ...
- Unity3D与JSP TomCatserver传递数据和文件( 二 ) Unity3D向java传输表单
扫码关注微信公众号,获取最新资源 经历了一天的工作.我又来更新啦...白天手欠,把上一个给删了.明天重写吧.. 废话不多说.我们先去Unity里创建一个能够输入username和password的登录 ...
- IOS 动态库问答
- UVA - 11077 Find the Permutations (置换)
Sorting is one of the most usedoperations in real life, where Computer Science comes into act. It is ...
- 关于联想超极本出现蓝屏Default Boot Device Missing or Boot Failed的解决办法
联想笔记本出现以下症状无法开机时: 解决方案:恢复BIOS默认设置,把硬盘设置为第一启动项. 若成功检测到硬盘并有EFI引导程序,那么恭喜你这就完事了,重启后就可以正常开机了. 但是,若在UEFI模式 ...
- jquery 页眉单行信息滚动显示
JSP: 下面是控制滚动的样式.将滚动的内容查询出来.放在一个div 或者别的容器里面,我这里使用的是<dt> <style> #newCglist{width:300px;h ...
- luogu1168 中位数
题目大意 给出一个长度为N的非负整数序列A[i],对于所有1 ≤ k ≤ (N + 1) / 2,输出A[1], A[3], -, A[2k - 1]的中位数.即前1,3,5,--个数的中位数. 题解 ...