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
显然,对于一个 aa % 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); }
相关文章推荐
- HDU 6090 Rikka with Graph (贪心+构造, 2017 Multi-Univ Training Contest 5)
- HDU 6127 Hard challenge (极角排序+二分, 2017 Multi-Univ Training Contest 7)
- HDU 6140 Hybrid Crystals (2017 Multi-Univ Training Contest 8)
- HDU 6096 String (字典树, 2017 Multi-Univ Training Contest 6)
- HDU 6125 Free from square (状压 dp , 2017 Multi-Univ Training Contest 7)
- HDU 6059 Kanade's trio (字典树, 2017 Multi-Univ Training Contest 3)
- HDU 6046 hash (HASH, 2017 Multi-Univ Training Contest 2)
- HDU 6133 Army Formations (树状数组, 2017 Multi-Univ Training Contest 8)
- HDU 6073 Matching In Multiplication (拓扑+DFS, 2017 Multi-Univ Training Contest 4)
- HDU 6074 Phone Call (LCA+并查集, 2017 Multi-Univ Training Contest 4)
- HDU 6072 Logical Chain (Biset+Kosaraju, 2017 Multi-Univ Training Contest 4)
- HDU 6065 RXD, tree and sequence (LCA, 2017 Multi-Univ Training Contest 3)
- HDU 6121 Build a tree (递归+特判, 2017 Multi-Univ Training Contest 7)
- HDU 6136 Death Podracing (2017 Multi-Univ Training Contest 8)
- HDU 6058 Kanade's sum (链表, 2017 Multi-Univ Training Contest 3)
- HDU 6071 Lazy Running (Dijstra, 2017 Multi-Univ Training Contest 4)
- HDU 6078 Wavel Sequence (dp + 树状数组, 2017 Multi-Univ Training Contest 4)
- HDU 6069 Counting Divisors (2017 Multi-Univ Training Contest 4)
- HDU 6143 Killer Names (容斥, 2017 Multi-Univ Training Contest 8)
- HDU 6138 Fleet of the Eternal Throne (后缀数组+字典树, 2017 Multi-Univ Training Contest 8)