1101:不定方程求解
时间限制: 1000 ms 内存限制: 65536 KB
提交数: 21316 通过数: 16928
【题目描述】
给定正整数a,b,c。求不定方程 ax+by=c 关于未知数x和y的所有非负整数解组数。
【输入】
一行,包含三个正整数a,b,c两个整数之间用单个空格隔开。每个数均不大于1000。
【输出】
一个整数,即不定方程的非负整数解组数。
分析:要求求出组数,那么直接循环得出结果时用一个计数器做递增操作即可。
#include<iostream>
//#include<iomanip>
//#include<cmath>
using std::cout;
using std::cin;
//using std::endl;
//using std::fixed;
//using std::setprecision;
//using std::pow;
int main()
{
int a = 0, b = 0, c = 0;
cin >> a >> b >> c;
int num=0;
for (int x = 0; x <= c; ++x)
{
for (int y = 0; y <= c; ++y)
{
if (a * x + b * y == c)
{
num++;
}
}
}
cout << num;
}
第四章完结撒花!