NC14309. Interview
描述
输入描述
The first line is the number of test cases. It's guaranteed that the test cases is not greater than 105.
Each test case contains two integers N and D (2 ≤ N ≤ 109, D = 1 or 2). D = 1 means Bob will be interviewed on the first day and D = 2 means Bob will be interviewed on the second day.
输出描述
Each test case contains one line with one integer. Let‘s assume the possibility be equal to the irreducible fraction P / Q. Print the value of P * Q-1 in the prime field of integers modulo 1000000007(109+7).
示例1
输入:
3 2 1 3 2 100 1
输出:
1 875000008 500000029
C++11(clang++ 3.9) 解法, 执行用时: 32ms, 内存消耗: 1272K, 提交时间: 2020-10-11 16:56:48
#include <bits/stdc++.h> using namespace std; const int P = 1e9 + 7; const int X = 1e9 + 8; int main() { int T; scanf("%d", &T); while (T--) { long long n; int o; scanf("%lld%d", &n, &o); if (o == 1) { printf("%d\n", ((n + 2) * X / 4) % P); } else { printf("%d\n", ((3 * n + 6) * X / 8) % P); } } return 0; }