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

来源:互联网 发布:闲鱼淘宝介入 编辑:程序博客网 时间:2024/06/04 18:22

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);}
阅读全文
0 0
原创粉丝点击