Created
June 3, 2010 14:34
-
-
Save yaotti/423956 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; | |
// calculate fib(n+2)-1 | |
int fib_total(long long int val1, long long int val2, long long int n) { | |
if (n < 1) return val2 - 1; | |
return fib_total(val2, val1+val2, n-1); | |
} | |
void solve(long long int n, int m, int c) { | |
int total = fib_total(1, 1, n) % 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++) { | |
string first, second; | |
first = i < pls ? "1" : "0"; | |
second = i < pls ? "0" : "-1"; | |
for (int j = 0; j < total - i; j++) { | |
cout << first; | |
if (j != total-1) cout << " "; | |
} | |
for (int j = 0; j < i; j++) { | |
cout << second; | |
if (j != i-1) cout << " "; | |
} | |
cout << endl; | |
} | |
} | |
} | |
int main(int argc, char **argv) | |
{ | |
int total = 0; | |
cin >> total; | |
long long int n; | |
int m; | |
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