#include<iostream> using namespace std; unsigned f(unsigned a, unsigned b, unsigned n) { if(n == 1 || n == 2) return 1; return (a * f(a, b, n-1) + b * f(a, b, n-2)) % 7; } int main() { unsigned a, b, n; while(cin >> a >> b >> n, a !=0 && b != 0 && n != 0) cout << f(a, b, n) << endl; return 0; }
#include<iostream> using namespace std; unsigned long f(unsigned long a, unsigned long b, unsigned long n) { if(n == 1 || n == 2) return 1; return (a * f(a, b, n-1) + b * f(a, b, n-2)) % 7; } int main() { unsigned long a, b, n; while(cin >> a >> b >> n, a !=0 && b != 0 && n != 0) cout << f(a, b, n) << endl; return 0; }
#include<iostream> using namespace std; int main() { const size_t array_size = 50; int a, b, n, parr[array_size] = {0, 1, 1}; while(cin >> a >> b >> n, a !=0 && b != 0 && n != 0) { for(size_t ix = 3; ix != array_size; ++ix) parr[ix] = (a * parr[ix - 1] + b * parr[ix - 2]) % 7; cout << parr[n%49] << endl; } return 0; }
同时欢迎提出不同意见,以帮助我改进,不胜感激!!!
——桑海整理