সংখ্যা N কি তিনটি কনsekutিভ ইন্টিজারের যোগফল হিসেবে লেখা যায়?
N = (y-1) + y + (y+1) = 3y → সুতরাং N % 3 == 0 হলে সম্ভব।
C++ কোড উদাহরণ
#include <iostream>
using namespace std;
bool isSumOf3Consecutive(int n) {
return (n % 3 == 0);
}
int main() {
int n = 27;
cout << (isSumOf3Consecutive(n) ? "Can be represented" : "Cannot be represented");
return 0;
}
আউটপুট
Can be represented