您的位置:首页 > 大数据 > 人工智能

HDU 6124 Euler theorem (2017 Multi-Univ Training Contest 7)

2017-08-15 21:11 639 查看

Problem

HazelFan is given two positive integers a,b, and he wants to calculate a mod b. But now he forgets the value of b and only remember the value of a, please tell him the number of different possible results.

已知 a ,求对于任意的 b ,a % b 有多少种可能。

Idea

显然,对于一个 a

a % a 余 0

a % (a-1) 余 1

a % (a-2) 余 2



当然,余数最大的取值为 < a/2 ,

∵ a 为偶数时, a % (a/2+1) 余 a/2-1, a % (a/2) 余 0 ; a 为奇数时, a % (a/2+1) 余 a/2, a%(a/2) 余 1 .

同时,任意一个 b > a ,a % b 余 a 。

故总共的可能的余数为 [0,(a+1)/2)⋃a ,共 a+12+1 个

Code

#include<bits/stdc++.h>
using namespace std;
int main()
{
int T, a;
scanf("%d", &T);
while(T-- && scanf("%d", &a))
printf("%d\n", (a+1)/2+1);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐