n%m
Time Limit:1000MS Memory Limit:65536K
Total Submit:313 Accepted:193
Description
求 1%m+2%m+3%m...+n%m的值。
Input
第一行有一个整数N表示有N组测试数据。
每组测试数据都有两个整数n,m( 0< n < 2^20 且 0 < m < 2014)
Output
求出每组 1%m+2%m+3%m...+n%m 的值。
Sample Input
2
3 2
63152 373
Sample Output
2
11731552
Hint
ahstu@icpc2014
Source
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AK1141 {
class Program {
static void Main(string[] args) {
int t = int.Parse(Console.ReadLine());
while (t-- > 0) {
string[] a = Console.ReadLine().Split();
long n = long.Parse(a[0]), m = long.Parse(a[1]);
long sum = 0;
for (int i = 1; i <= n; i++)
sum += i % m;
Console.WriteLine(sum);
}
}
}
}