cpp。求Fibonacci分数序列的前n项之和。Fibonacci分数序列的首项为2/1,后面依次是:3/2,5/3,8/5,13/8,21/13…… 输入格式:…
- User
cpp。求Fibonacci分数序列的前n项之和。Fibonacci分数序列的首项为2/1,后面依次是:3/2,5/3,8/5,13/8,21/13…… 输入格式:
测试数据由多组,处理到文件尾。每组测试输入一个正整数n(2≤n≤20)。
输出格式:
对于每组测试,输出Fibonacci分数序列的前n项之和。结果保留6位小数。
- Assistant
#include #include
using namespace std;
int main() { int n; while (cin >> n) { double sum = 2.0; double a = 2.0, b = 1.0; for (int i = 2; i <= n; i++) { double temp = a + b; sum += temp; b = a; a = temp; } cout << fixed << setprecision(6) << sum << endl; }
return 0;}
- User
cpp。有n匹马,驮n担货,大马驮3担,中马驮2担,两匹小马驮1担,问有大、中、小马各多少匹? 输入格式:
测试数据由多组,处理到文件尾。每组测试输入一个正整数n(8≤n≤1000)。
输出格式:
对于每组测试,逐行输出所有符合要求的大、中、小马的匹数(可为0)。要求按大马数从小到大的顺序输出,每两个数字之间留一个空格。
- Assistant
#include
using namespace std;
int main() { int n; while (cin >> n) { bool found = false; for (int big = 0; big <= n / 3; big++) { for (int medium = 0; medium <= n / 2; medium++) { int small = n - big * 3 - medium * 2; if (small >= 0 && small % 2 == 0) { cout << big << " " << medium << " " << small / 2 << endl; found = true; } } } if (!found) { cout << "No solution" << endl; } }
return 0;}
- User
cpp。有n匹马,驮n担货,大马驮3担,中马驮2担,两匹小马驮1担,问有大、中、小马各多少匹? 输入格式:
测试数据由多组,处理到文件尾。每组测试输入一个正整数n(8≤n≤1000)。
输出格式:
对于每组测试,逐行输出所有符合要求的大、中、小马的匹数(可为0)。要求按大马数从小到大的顺序输出,每两个数字之间留一个空格。
- Assistant
#include
using namespace std;
int main() { int n; while (cin >> n) { bool found = false; for (int big = 0; big <= n / 3; big++) { for (int medium = 0; medium <= n / 2; medium++) { int small = n - big * 3 - medium * 2; if (small >= 0 && small % 2 == 0) { cout << big << " " << medium << " " << small / 2 << endl; found = true; } } } if (!found) { cout << "No solution" << endl; } }
return 0;}
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.