-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCook-Off-palindromes.c
More file actions
70 lines (57 loc) · 868 Bytes
/
Cook-Off-palindromes.c
File metadata and controls
70 lines (57 loc) · 868 Bytes
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
67
68
69
70
#include<stdio.h>
#include<math.h>
long gcd(long , long);
void Divbygcd(long,long);
long C(int,int);
int main()
{
int T,n,i,k,ans;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
if(n==1)
{
ans=26;
}
else if((n%2)==0)
{
k = n/2;
}
else
{
k = (n/2)+1;
}
for(i=0;i<k;i++)
{
ans = ans + C(26,i) ;
}
}
printf("%d",ans);
}
return 0;
}
long gcd(long a,long b) {
if (a%b==0) return b;
else
return gcd(b,a%b);
}
void Divbygcd(long &a,long &b) {
long g=gcd(a,b);
a/=g;
b/=g;
}
long C(int n,int k){
long numerator=1,denominator=1,toMul,toDiv,i;
if (k>n/2) k=n-k;
for (i=k;i;i--) {
toMul=n-k+i;
toDiv=i;
Divbygcd(toMul,toDiv);
Divbygcd(numerator,toDiv);
Divbygcd(toMul,denominator);
numerator*=toMul;
denominator*=toDiv;
}
return numerator/denominator;
}