直接打表找规律
HazelFan is given two positive integers a,ba,b, and he wants to calculate amodbamodb. But now he forgets the value of bb and only remember the value of aa, please tell him the number of different possible results.
InputThe first line contains a positive integer T(1≤T≤5)T(1≤T≤5), denoting the number of test cases.
For each test case:
A single line contains a positive integer a(1≤a≤109)a(1≤a≤109).OutputFor each test case:
A single line contains a nonnegative integer, denoting the answer.
Sample Input
2 1 3
Sample Output
2 3
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<sstream> #include<algorithm> #include<queue> #include<deque> #include<iomanip> #include<vector> #include<cmath> #include<map> #include<stack> #include<set> #include<memory> #include<list> #include<string> using namespace std; typedef long long LL; typedef unsigned long long ULL; #define MAXN 1009 #define L 31 #define INF 1000000009 #define eps 0.00000001 LL n; int main() { int T; scanf("%d", &T); while (T--) { scanf("%lld", &n); if (n & 1) n++; printf("%lld\n", n / 2 + 1); } }
本文介绍了一个算法问题,即给定一个正整数a,计算a的m次方模b的不同可能结果的数量,但b的值未知。通过分析,发现当a为奇数时,结果数量为(a+1)/2,否则结果数量为a/2+1。文章提供了一段C++代码实现,用于解决该问题。
1023

被折叠的 条评论
为什么被折叠?



