如果这篇博客帮助到你,可以请我喝一杯咖啡~
CC BY 4.0 (除特别声明或转载文章外)
Built with Qinghuai and Ari Factor
#include <bits/stdc++.h>
using namespace std;
int t, n, a, b;
int main(void)
{
cin >> t;
for (int ii = 1; ii <= t; ii++)
{
cin >> n;
b = 0;
for (int i = 1; i <= n; i++)
{
cin >> a;
if (a % 3)
b = 1;
}
printf("Case #%d: ", ii);
if (b)
printf("No\n");
else
printf("Yes\n");
}
}
Color
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6 + 10;
const LL mod = 1e9 + 7ll;
int T;
LL n, m, k;
LL jc[maxn], jcn[maxn];
inline LL mpow(LL a, LL b)
{
LL ret = 1, tem = a;
while (b)
{
if (b & 1)
ret = ret * tem % mod;
tem = tem * tem % mod;
b >>= 1;
}
return ret;
}
inline LL c(LL a, LL b)
{
return jc[a] * jcn[b] % mod * jcn[a - b] % mod;
}
void init()
{
jc[1] = jc[0] = 1;
jcn[1] = jcn[0] = 1;
for (int i = 2; i <= 1000000; i++)
jc[i] = jc[i - 1] * i % mod, jcn[i] = mpow(jc[i], mod - 2);
}
LL Pow(LL a, LL k)
{
if (k == 0)
return 1ll;
LL now = Pow(a, k / 2);
now = now * now % mod;
if (k % 2 == 1)
now = now * a % mod;
return now;
}
LL made(LL p, LL q)
{
LL now = p * Pow(p - 1, n - 1) % mod * c(k, q) % mod;
return now;
}
LL cc(LL m, LL k)
{
LL now = 1ll;
for (LL i = m; i >= m - k + 1; i--)
now = now * i % mod;
now = now * jcn[k] % mod;
return now;
}
int main()
{
scanf("%d", &T);
init();
for (int t = 1; t <= T; t++)
{
scanf("%lld%lld%lld", &n, &m, &k);
LL d = 1ll, s = 0, ans = 0;
for (LL i = k; i >= 1; i--)
{
LL now = made(i, s);
ans = (ans + d * now % mod + mod) % mod;
d = d * (-1ll);
s++;
}
ans = ans * cc(m, k) % mod;
printf("Case #%d: %lld\n", t, ans);
}
return 0;
}
Last Defence
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a, b, c, t, ans;
ll deal(ll a, ll b)
{
if (a == 0 && b == 0)
return 1;
if (b == 0)
return 2;
if (a % b == 0)
return a / b + 1;
ll c = a % b;
return a / b + deal(max(b, c), min(b, c));
}
int main(void)
{
cin >> t;
for (int ii = 1; ii <= t; ii++)
{
cin >> a >> b;
ans = deal(max(a, b), min(a, b));
printf("Case #%d: %lld\n", ii, ans);
}
}