Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:

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.

What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way?

找规律。

右上角(2n+1)^2

左上角(2n+1)^2-(2n+1)+1

左下角(2n+1)^2-4*n

右下角(2n+1)^2-6*n

2n+1<=1001    n<=500

#include <iostream>
#include <string>
using namespace std; int main()
{
int n = 500;
long long res = 1;
for (int i = 1; i <= 500; i++)
{ int tmp = (2 * i + 1)*(2 * i + 1);
res += tmp*4 - (2 * i + 1) + 1 - 4 * i - 6 * i;
}
cout << res << endl;
system("pause");
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

最新文章

  1. json数据转换失败json_last_error int(4)
  2. nohup输入密码后继续后台运行
  3. Javascript倒计时组件new TimeSpan(hours, minutes, minutes)
  4. Using Amazon API Gateway with microservices deployed on Amazon ECS
  5. 一种JavaScript 类的设计模式
  6. TOP/ORDER BY 顺序(转)
  7. 虚拟主机、VPS、云主机以及独立服务器的关系
  8. Umbraco(3) - CSS &amp; Javascript(翻译文档)
  9. android136 360 拖拽
  10. codeforces 553D . Nudist Beach 二分
  11. 搜狐畅游:每月给员工直系长辈2000元爱孝薪_企业新闻_265G产业频道
  12. 剑指offer 连续子序列和
  13. UVa 532 - Dungeon Master
  14. 【Alpha】第六次Daily Scrum Meeting
  15. JAVAWEB开发环境搭建,附JDK开发环境一键配置批处理bat
  16. fiddler 抓取 安卓模拟器 https包
  17. 怎样在win7 IIS中部署网站
  18. ecshop jquery 冲突
  19. 两次内存断点法寻找OEP
  20. Hadoop vs Spark性能对比

热门文章

  1. iOS_01_什么是ios
  2. 安装orabbix
  3. java韩顺平老师视频有需要可以留言
  4. PHP URL参数获取方式的四种例子
  5. u-boot分析1:Nandflash、Norflash启动
  6. 【例题5-1 UVA 10474 】Where is the Marble?
  7. php实现合并两个排序的链表(很多情况下新建数组装东西比连东西逻辑快很多)($cur=$cur-&gt;next;的理解)
  8. Sphinx+MySQL5.1x+SphinxSE+mmseg中文分词
  9. mycat server.xml 配置文件详解
  10. Android 如何Android中自定义Navigationbar