Skip to content

Instantly share code, notes, and snippets.

@yaotti
Created June 3, 2010 13:40
Show Gist options
  • Save yaotti/423894 to your computer and use it in GitHub Desktop.
Save yaotti/423894 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
using namespace std;
long long int fib(int n)
{
double sqrt5 = sqrt(5);
return (1.0 / sqrt5) * (pow((1.0+sqrt5) / 2, n) - pow((1.0-sqrt5) / 2, n));
}
void solve(long long int n, long long int m, int c) {
long long int total = 0;
for (int i = 1; i <= n; i++) {
total += fib(i) % m;
}
total %= m;
if (total == 0 || total % 2 == 1) {
cout << "Case " << c << ": No" << endl;
}else {
cout << "Case " << c << ": Yes" << endl;
int pls = total / 2;
for (int i = 0; i < total; i++) {
if (i < pls) {
for (int j = 0; j < total - i; j++) {
cout << "-1";
if (j != total-1) cout << " ";
}
for (int j = 0; j < i; j++) {
cout << "0";
if (j != i-1) cout << " ";
}
}else {
for (int j = 0; j < total - i; j++) {
cout << "0";
if (j != total-1) cout << " ";
}
for (int j = 0; j < i; j++) {
cout << "1";
if (j != i-1) cout << " ";
}
}
cout << endl;
}
}
}
int main(int argc, char **argv)
{
int total = 0;
cin >> total;
long long int m, n;
for (int i = 0; i < total; i++) {
cin >> n >> m;
solve(n, m, i+1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment