- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long int
- #define M 1000000007
- #define N 2000006
- ll fact[N];
- ll bigmod(ll p, ll q){
- if(q == 1) return p%M;
- if(q%2 == 0){
- ll a = bigmod(p, q/2);
- return ((a%M)*(a%M))%M;
- }
- else {ll a = bigmod(p, q-1);return (a*p)%M;}
- }
- void pre(){
- fact[0] = 1;
- for(int i = 1; i <N; i++) fact[i] = (i*(fact[i-1]%M))%M;
- }
- int main(){
- pre();
- int ts;
- scanf("%d", &ts);
- for(int k = 1; k <= ts; k++){
- int n, r;
- scanf("%d%d", &n, &r);
- ll s = bigmod((fact[n]*fact[r-1])%M,M-2)%M;
- ll p = (fact[n+r-1]*s)%M;
- printf("Case %d: %lld\n", k,p);
- }
- return 0;
- }
- /*
- using namespace std;
- #include <bits/stdc++.h>
- const long long mod = 1000000007ll;
- const int mn = 2000002;
- long long fact[mn];
- long long mod_pow(long long b, long long e, long long m) {
- long long ans = 1;
- while (e > 0) {
- if (e & 1)
- ans = (ans * b) % m;
- b = (b * b) % m;
- e >>= 1;
- }
- return ans;
- }
- void solve() {
- long long n, k;
- cin >> n >> k;
- long long num = fact[n + k - 1];
- long long den = (fact[n] * fact[k - 1]) % mod;
- printf("%lld\n", (num * mod_pow(den, mod - 2, mod)) % mod);
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- fact[0] = 1;
- for (int i = 1; i < mn; ++i) {
- fact[i] = (i * fact[i - 1]) % mod;
- }
- int tc;
- cin >> tc;
- for (int i = 0; i < tc; ++i) {
- printf("Case %d: ", i + 1);
- solve();
- }
- return 0;
- }
- */
Saturday, 29 July 2017
Lightoj 1102 - Problem Makes Problem
Subscribe to:
Post Comments (Atom)
Most Featured Post
Lightoj 1159 - Batman
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
-
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
No comments:
Post a Comment