(Problem 28)Number spiral diagonals
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的更多相关文章
- (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 + ...
- (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 ...
- (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 ...
- (Problem 70)Totient permutation
Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...
- (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 ...
- (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 ...
- (Problem 49)Prime permutations
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual ...
- (Problem 37)Truncatable primes
The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...
- (Problem 36)Double-base palindromes
The decimal number, 585 = 10010010012(binary), is palindromic in both bases. Find the sum of all num ...
随机推荐
- 《windows程序设计》学习_3.1:画出雷区,左键的使用
#include<windows.h> #include "resource.h" LRESULT CALLBACK WndProc (HWND, UINT, WPAR ...
- UBER人民优步司机注册攻略
注意:本文驾驶证行驶证图片为本人拍摄,请广大网友勿作它用 转载请修改! 详细的介绍注册优步uber司机端步骤; uber对司机的要求: 车辆为本地牌照 车龄在5年以内 裸车价格在10万以上 目 ...
- oracle中clob字段的使用
oracle中定义了一个字段是clob的,由于用的是ssh的框架,结果在面向对象存取的时候出现clob类型字段和String类型字段的转换问题.开始查阅了clob字段和String字段的相互转换的方法 ...
- CentOS6.6普通用户使用sudo命令借用root用户权限
一.描写叙述 普通用户hadoop使用:tar -xzvf ns2.35.tar.gz命令解压文件,系统提示找不到该文件,无法打开该文件夹,于是想到使用sudo命令借用root用户的权限:sudo t ...
- 简单使用SimpleCursorAdapter
http://my.oschina.net/javaeye/blog/14846 果使用Sqlite,建议和ContentProvider结合使用.这样数据库的生命周期就不用自己管了.然后,如果要在比 ...
- Android TextView 实现文字大小不同和文字颜色不同
效果图如下: 关键代码如下: StringBuffer sb = new StringBuffer(); if(day > 0) { sb.append("<a href=\&q ...
- hasOwnProperty和isPrototypeOf方法使用
hasOwnProperty():判断对象是否有某个特定的属性.必须用字符串指定该属性.(例如,o.hasOwnProperty("name")) //复制自w3cschool ...
- 文件上传下载样式 --- bootstrap
在平时工作中,文件上传下载功能属于不可或缺的一部分.bootstrap前端样式框架也使用的比较多,现在根据bootstrap强大的样式模板,自定义一种文件下载的样式. 后续会使用spring MVC框 ...
- Javascript Duff装置 循环展开(Javascript Loop unrolling Duff device)
Javascript 中会用到for 循环,当要循环的数据记录很多的时候,可能会对性能产生很大影响.这时我们可以考虑展开for循环,这时就要用到Duff装置(Duff Device). 先来看一个小例 ...
- C# 自定义控件的一些文章和博客
http://blog.csdn.net/songkexin/archive/2009/12/08/4961215.aspx http://www.cnblogs.com/yuanfan/archiv ...