题目简介
Let r be the remainder when (a-1)n + (a+1)n is divided by a2 .
For example, if a = 7 and n = 3, then r = 42: ( 63 + 83 = 728 )%49= 42. And as n varies, so too will r, but for a = 7 it turns out that rmax = 42.
The question is when given a , you must find rmax.
The first line will be a number N(<=100), means that there’re N test cases , Then N lines follow,each with a number a(3<=a<=10000) as described above.
说明
对于奇数,答案是a(a-1),对于偶数则为a(a-2)。要求模a^2最大,让一个因子为a另一个尽可能接近a就可以了——这是由模运算的“循环”特性决定的。
#include <stdio.h>
int main(void)
{
int t, a, r;
scanf("%d", &t);
while(t--){
scanf("%d", &a);
r = 2 * a * ((a - 1) / 2);
printf("%d\n", r);
}
return 0;
}