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. nginx 编译参数

    jrhnpt01:/root# nginx -V nginx version: nginx/1.7.7 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (G ...

  2. HTML5 RPG游戏示例

    演示地址 点击打开链接

  3. Head First设计模式学习笔记

    最近在学C++,直接语法之后觉得不太有意思,直接做项目又觉得太肤浅.正好之前一直想学设计模式来着,可惜之前一直在玩C,所以没有机会深入学习,于是决定用C++把设计写一遍.看了点GOF的<设计模式 ...

  4. linux内核之网络协议栈

    https://www.ibm.com/developerworks/cn/linux/l-ntflt/

  5. ES配置详解

    elasticsearch的config文件夹里面有两个配置文件:elasticsearch.yml和logging.yml,第一个是es的基本配置文件,第二个是日志配置文件,es也是使用log4j来 ...

  6. 浅谈Servlet(二)

    1.forward(请求的转发)和redirect(重定向) 目的:都是为了把一个Servlet的功能,拆分到多个Servlet中,便于后续代码的维护. a.forward(请求转发) (1).如何在 ...

  7. [Swust OJ 632]--集合运算(set容器)

    题目链接:http://acm.swust.edu.cn/problem/632/ Time limit(ms): 1000 Memory limit(kb): 65535   Description ...

  8. BZOJ 2301 Problem b(莫比乌斯反演+分块优化)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37166 题意:对于给出的n个询问,每次求有多少个数对(x,y),满 ...

  9. La=LaULb (单链表)

    #include<stdio.h> typedef struct LNode { int data; struct LNode *next; }LNode,*LinkList; void ...

  10. mysql查询数据库中包含某字段(列名)的所有表

    SELECT TABLE_NAME '表名',TABLE_SCHEMA '数据库名',ORDINAL_POSITION '顺序',COLUMN_NAME '字段',DATA_TYPE '类型' ,CH ...