Pagini recente » Cod sursa (job #1361981) | Cod sursa (job #1801232) | Cod sursa (job #1099353) | Cod sursa (job #1397730) | Cod sursa (job #2913162)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
class Solution {
public:
void rezolvare (string fileInput, string fileOutput){
ifstream fileIn; fileIn.open(fileInput, ios::in);
ofstream fileOut; fileOut.open(fileOutput, ios::out);
// From here we start the problem.
fileIn >> number;
countFractii = number;
countFractii += trunc(number * number / 4);
long long int tempNumber = number;
if (number % 2 == 0) tempNumber = number - 2;
else tempNumber = number - 1;
long long int modN = number * 2;
if (modN % 3 != 0) {
while (true) {
modN++;
if (modN % 3 == 0) break;
}
}
countFractii += modN / 3 * tempNumber / 2;
fileOut << countFractii;
fileIn.close(); fileOut.close();
}
private:
long long int number{0};
long long int countFractii = 0;
};
int main()
{
Solution s;
s.rezolvare("fractii.in", "fractii.out");
return 0;
}