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. JSP打印九九乘法表

    ##index.jsp: <%@ page language="java" import="java.util.*" pageEncoding=" ...

  2. 追踪神秘的成都Uber:月入2万元是现实还是传说

    4月6日,一个视频在网上疯转——在上海,明星佟大为驾驶着售价近100万元的特斯拉电动汽车,作为一名Uber的司机满市转悠着拉客. Uber——优步,如果你不知道这个词,那就OUT了.就是这样的一款软件 ...

  3. Linux中环境变量到底写在哪个文件中?解析login shell 和 no-login shell

    login shell:取得bash 时需要完整的登入流程,就称为login shell.举例来说,同tty1~tty6登入时, 需要输入用户名和密码,此时取得的bash就称为login shell ...

  4. JavaScipt实现倒计时方法总结

    JavaScript中提供了两种实现计时.延时的方法,分别如下: 一. t = setTimeout(“function()", millisecond) 与 clearTimeout(t) ...

  5. 关于typedef之四种用途 和 两个陷进

    typedef用来声明一个别名,typedef后面的语法,是一个声明.本来笔者以为这里不会产生什么误解的,但结果却出乎意料,产生误解的人 不在少数.罪魁祸首又是那些害人的教材.在这些教材中介绍type ...

  6. WCF 出现无法理解Soap Action问题?

    在使用wcf部署到asp.net上时,遇到了,“无法理解soap Action 问题,”最简单的解决办法是更换NET framwork 高本版的框架. 不过不更换net framwork 框架,能否解 ...

  7. jQuery的hover()方法(笔记)

    因为mouseover和mouseout经常一起写,所以出现了hover() hover(function(){},function(){});第一个参数为鼠标移入运行的函数,第二个为鼠标离开运行的函 ...

  8. BootStrap 智能表单系列 八 表单配置json详解

    本章属于该系列的高级部分,将介绍表单中一些列的配置 1.config列的配置: 主要用于控制布局 :config:{autoLayout:true|'1,2,2,4'} true:根据配置项最里层的数 ...

  9. vs2010更改默认环境设置

    今天刚刚装vs2010手欠点击了新建团队项目,在百度上各种查找说让我去 visual studio tools的命令提示中进行 devenv命令行修改 ResetString但是没找到我设置文件的路径 ...

  10. Laravel5 学习与使用(一)

    2015-07-04 (1)  安装Laravel框架 ① 安装前的准备工作 使用Apache24 + PHP 5.6 + MySQL 开发环境完成PHP网站开发,所以Laravel的安装是建立在以上 ...