【题目描述】
给定正整数a,b,c。求不定方程 ax+by=c 关于未知数x和y的所有非负整数解组数。
【输入】
一行,包含三个正整数a,b,c,两个整数之间用单个空格隔开。每个数均不大于1000。
【输出】
一个整数,即不定方程的非负整数解组数。
【输入样例】
2 3 18
【输出样例】
4
【题目链接】
#include <stdio.h>
int countSolutions(int a, int b, int c)
{
int count = 0, x;
for (x = 0; x <= c / a; x++)
{
int remainder = c - a * x;
if (remainder % b == 0)
count++;
}
return count;
}
int main()
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
int result = countSolutions(a, b, c);
printf("%d", result);
return 0;
}