SPOJ15710 Iterated sums
2016-04-17 10:31
323 查看
Please compute the sum of squares for the given numbers: a, a+1, ...,
b-1, b.
b <=100.
简单,直接贴代码
代码如下:
<?php
$debug = false;
$file = STDIN;
if ($debug)
{
$file = fopen('./spoj.txt', 'r');
}
while (($line = fgets($file)) !== false)
{
$line = trim($line);
if (empty($line)) break;
sscanf($line, "%d%d", $a, $b);
$sum = 0;
for ($i = $a; $i <= $b; $i++)
{
$sum += $i * $i;
}
echo $sum.PHP_EOL;
}
if ($debug) fclose($file);
?>
b-1, b.
Input
Two numbers: a and b separated by space, where 1 <= a <=b <=100.
Output
Computed sum: a*a + (a+1)*(a+1)+ ... +(b-1)*(b-1) +b*bExample
Input: 1 4 Output: 30
Example 2
Input: 5 6 Output: 61
简单,直接贴代码
代码如下:
<?php
$debug = false;
$file = STDIN;
if ($debug)
{
$file = fopen('./spoj.txt', 'r');
}
while (($line = fgets($file)) !== false)
{
$line = trim($line);
if (empty($line)) break;
sscanf($line, "%d%d", $a, $b);
$sum = 0;
for ($i = $a; $i <= $b; $i++)
{
$sum += $i * $i;
}
echo $sum.PHP_EOL;
}
if ($debug) fclose($file);
?>
相关文章推荐
- C++封装、继承、多态
- 第七周学习进度
- linux第四次读书笔记
- LightOJ 1341 Aladdin and the Flying Carpet【整数分解】
- Kali 强大的抓包工具 WIRESHARK
- LightOJ 1341 Aladdin and the Flying Carpet【整数分解】
- LightOJ 1341 Aladdin and the Flying Carpet【整数分解】
- 视频封装格式之mkv--1
- java native关键字
- 20145236 《Java程序设计》实验二实验报告
- 进程间的通信方式与进程间同步方式
- php session和cookie
- IE请求和响应报文解释
- BestCoder Round #80(B)高精度
- 一些linux的基本操作
- Oracle 11g standby主从配置
- Oracle笔记(三) Scott用户的表结构
- 水仙花数的输出
- 武器游戏
- 多文件游戏