Created
June 3, 2010 13:40
-
-
Save yaotti/423894 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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