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?

原题大意:

从数字1开始向右顺时针方向移动,可以得到如下的5×5的螺旋:

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

可以算出对角线上数字之和是101.        1001×1001的螺旋中对角线上数字之和是多少?

//(Problem 28)Number spiral diagonals
// Completed on Thu, 25 Jul 2013, 14:31
// Language: C
//
// 版权所有(C)acutus (mail: acutus@126.com)
// 博客地址:http://www.cnblogs.com/acutus/ #include<stdio.h>
void countSum()
{
int i=;
int sum=;
int n=(+)/-;
while(n--)
{
int t=i*i;
sum+=(*t-(i-)*);
i=i+;
}
printf("%d\n",sum);
} int main()
{
countSum();
return ;
}
Answer:
669171001

(Problem 28)Number spiral diagonals的更多相关文章

  1. (Problem 17)Number letter counts

    If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + ...

  2. (Problem 42)Coded triangle numbers

    The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...

  3. (Problem 41)Pandigital prime

    We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly o ...

  4. (Problem 70)Totient permutation

    Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...

  5. (Problem 74)Digit factorial chains

    The number 145 is well known for the property that the sum of the factorial of its digits is equal t ...

  6. (Problem 46)Goldbach's other conjecture

    It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a ...

  7. (Problem 49)Prime permutations

    The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual ...

  8. (Problem 37)Truncatable primes

    The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...

  9. (Problem 36)Double-base palindromes

    The decimal number, 585 = 10010010012(binary), is palindromic in both bases. Find the sum of all num ...

随机推荐

  1. Linux下安装memcached

    Linux下安装memcached 1.运行memcached需要本文开头介绍的libevent库 $ sudo yum install libevent libevent-deve 2.下载安装me ...

  2. VS2010/MFC常用控件:图片控件Picture Control

    图片控件Picture Control 本节主要讲一种简单实用的控件,图片控件Picture Control.我们可以在界面某个位置放入图片控件,显示图片以美化界面. 图片控件简介 图片控件和前面讲到 ...

  3. 7kb的javascript日期操作类库(XDate)

    A Modern JavaScript Date Library XDate is a thin wrapper around JavaScript's native Date object that ...

  4. python 使用xrld

    下载xrld.要对应合适的python版本: 下载tar.gz包.解压 通过cmd进入该目录. setup.py build setup.py install 安装成功: 添加路径: from sys ...

  5. SharePoint2010添加webpart找不到内容编辑器

    1.开启相关网站集功能.2.若还是找不到可以在其它有内容编辑器的站点下,在“Web 部件”中找到并下载内容编辑器,上传至本站点即可.

  6. SQL Server2012新特性概述

    公司最近要升级数据库,SQL Server 2008R2-->2012.再开始升级之前先找了点资料分析一下2012的新特性和功能,提前预热一下. 2012中主要关注一下三个领域: 性能:改进的核 ...

  7. java中如何计算两个时间段的月份差

    直接计算,先取得两个日期的年份和月份,月份差=(第二年份-第一年份)*12 + 第二月份-第一月份

  8. GDI+ 对象释放崩溃的问题

    确保在Gdiplus::GdiplusShutdown(m_gdiplusToken); 之前delete 掉GDI+的对象,例如:delete *pBitmap; 如果先Gdiplus::Gdipl ...

  9. mysql 本机root密码忘记

    1.找到对应的my.conf,在mysqld节点添加:skip-grant-tables  2.重启mysql 即可无密登录 3.update user表中的密码后,去除skip-grant-tabl ...

  10. SVN 无法连接主机:由于目标计算机积极拒绝,无法连接

    问题:使用追溯功能时因为时间太长,所以强行关闭了SVN;当再次连接的时候就发现不能连接到SVN了,错误消息: 无法连接主机:由于目标计算机积极拒绝,无法连接 解决:重启一下服务器的SVN 服务就可以了