-
Notifications
You must be signed in to change notification settings - Fork 0
/
KYSXD_3335.cpp
66 lines (56 loc) · 1.37 KB
/
KYSXD_3335.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//"""
//#KYSXD - Problema 3335
//Dr. B - Tree II
//"""
//Status:
//"""
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
typedef unsigned long long ulong;
int paridad(int n) {
return (n%2 == 0) ? 0 : 1;
}
int objetos(int total, int contados){
return contados - paridad(total);
}
ulong int potencia(int a, int p){
ulong int resultado = 1;
for (int i = 0; i < p; i++) {
resultado = (resultado*a)%1000000007;
}
return resultado;
}
ulong int elevar(int a, int p){
if (p == 0) return 1;
return a*potencia(a, p-1);
}
ulong int combinaciones(int n, int k) {
if (k == 0) return 1;
return (n * combinaciones(n - 1, k - 1)) / k;
}
int restantes(int n, int r){
return n - 2*r + paridad(n);
}
int main() {
int caso, n, r;
ulong int total;
scanf("%d", &caso);
for (int i = 1; i <= caso; i++) {
scanf("%d %d", &n, &r);
if (n < r || int(n/2) + paridad(n) < r) {
printf("%d\n", 0);
}
else {
total = combinaciones(int(n/2), objetos(n,r)) % 1000000007;
total = (total*potencia(10, r)) % 1000000007;
total = (total*potencia(10, restantes(n,r)/2)) % 1000000007;
total = (total*potencia(9, restantes(n,r)/2)) % 1000000007;
printf("%lld\n",total);
}
}
return 0;
}