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. 《windows程序设计》学习_3.1:画出雷区,左键的使用

    #include<windows.h> #include "resource.h" LRESULT CALLBACK WndProc (HWND, UINT, WPAR ...

  2. UBER人民优步司机注册攻略

        注意:本文驾驶证行驶证图片为本人拍摄,请广大网友勿作它用 转载请修改! 详细的介绍注册优步uber司机端步骤; uber对司机的要求: 车辆为本地牌照 车龄在5年以内 裸车价格在10万以上 目 ...

  3. oracle中clob字段的使用

    oracle中定义了一个字段是clob的,由于用的是ssh的框架,结果在面向对象存取的时候出现clob类型字段和String类型字段的转换问题.开始查阅了clob字段和String字段的相互转换的方法 ...

  4. CentOS6.6普通用户使用sudo命令借用root用户权限

    一.描写叙述 普通用户hadoop使用:tar -xzvf ns2.35.tar.gz命令解压文件,系统提示找不到该文件,无法打开该文件夹,于是想到使用sudo命令借用root用户的权限:sudo t ...

  5. 简单使用SimpleCursorAdapter

    http://my.oschina.net/javaeye/blog/14846 果使用Sqlite,建议和ContentProvider结合使用.这样数据库的生命周期就不用自己管了.然后,如果要在比 ...

  6. Android TextView 实现文字大小不同和文字颜色不同

    效果图如下: 关键代码如下: StringBuffer sb = new StringBuffer(); if(day > 0) { sb.append("<a href=\&q ...

  7. hasOwnProperty和isPrototypeOf方法使用

    hasOwnProperty():判断对象是否有某个特定的属性.必须用字符串指定该属性.(例如,o.hasOwnProperty("name"))  //复制自w3cschool ...

  8. 文件上传下载样式 --- bootstrap

    在平时工作中,文件上传下载功能属于不可或缺的一部分.bootstrap前端样式框架也使用的比较多,现在根据bootstrap强大的样式模板,自定义一种文件下载的样式. 后续会使用spring MVC框 ...

  9. Javascript Duff装置 循环展开(Javascript Loop unrolling Duff device)

    Javascript 中会用到for 循环,当要循环的数据记录很多的时候,可能会对性能产生很大影响.这时我们可以考虑展开for循环,这时就要用到Duff装置(Duff Device). 先来看一个小例 ...

  10. C# 自定义控件的一些文章和博客

    http://blog.csdn.net/songkexin/archive/2009/12/08/4961215.aspx http://www.cnblogs.com/yuanfan/archiv ...