একটি টাকা পরিমাণ দেওয়া আছে যা চুকাতে হবে, মনে করুন pay_rupees এবং দুটি ধরনের ব্যাংক নোট আছে অনলিমিটেড পরিমাণে যাদের মান যথাক্রমে Rupees_amount_1 এবং Rupees_amount_2। লক্ষ্য হলো pay_rupees কে ঠিক distribution_total সংখ্যক নোট দিয়ে চুকানো এবং Rupees_amount_1 টাইপের নোট কতটিতে লাগবে তা গণনা করা। যদি কোনো সমাধান না থাকে তবে -১ রিটার্ন করা হয়।
ইনপুট
Rupees_amount_1 = 1, Rupees_amount_2 = 5, pay_Rupees = 11, distribution_total = 7
আউটপুট
Count of number of currency notes needed are: 6
ব্যাখ্যা
6×1 + 5×1 = 11 এবং নোট = 6+1 = 7
ইনপুট
Rupees_amount_1 = 2, Rupees_amount_2 = 3, pay_Rupees = 10, distribution_total = 4
আউটপুট
Count of number of currency notes needed are: 2
ব্যাখ্যা
2×2 + 3×2 = 10 এবং নোট = 2+2 = 4
প্রোগ্রামে ব্যবহৃত পদ্ধতি:
মনে করুন a1 = টাইপ ১ নোটের সংখ্যা এবং N = মোট নোটের সংখ্যা। P পরিমাণ চুকাতে হলে সমীকরণগুলো হবে:
a1*(Rupees_amount_1) + (N-a1)*(Rupees_amount_2) = PP = a1*(Rupees_amount_1) + N*(Rupees_amount_2) - a1*(Rupees_amount_2)P - N*(Rupees_amount_2) = a1*(Rupees_amount_1 - Rupees_amount_2)a1 = (P - N*Rupees_amount_2) / (Rupees_amount_1 - Rupees_amount_2)- যদি
a1ইন্টিজার হয় তবে সমাধান আছে, অন্যথায় -১ রিটার্ন।
উদাহরণ
#include <bits/stdc++.h>
using namespace std;
int notes_needed(int Rupees_amount_1, int Rupees_amount_2, int pay_Rupees, int distribution_total) {
int count = 0;
int total = pay_Rupees - (Rupees_amount_2 * distribution_total);
int total_given = Rupees_amount_1 - Rupees_amount_2;
if (total % total_given == 0) {
count = total / total_given;
return count;
} else {
return -1;
}
}
int main() {
int Rupees_amount_1 = 1;
int Rupees_amount_2 = 5;
int pay_Rupees = 11;
int distribution_total = 7;
cout << "Count of number of currency notes needed are: " << notes_needed(Rupees_amount_1, Rupees_amount_2, pay_Rupees, distribution_total);
return 0;
}
আউটপুট
Count of number of currency notes needed are: 6