EOJ 2784/Project Euler 120改 remainder

题目简介


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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值