#include "bits/stdc++.h" using namespace std; #define INIT ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define _CRT_SECURE_NO_WARINGS #define ALL(obj) (obj).begin(),(obj).end() #define SORT(obj) sort(ALL(obj)) #define rep(i,n) for(int i = 0; i < (n); ++i) #define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<; using VI = vector; using VP = vector

; templatebool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } #pragma region vector入出力用 template istream& operator >> (istream& is, vector& vec) { for (T& x : vec) is >> x; //for(int i=0; i> x[i]; とかでもいいです。 return is; } template ostream& operator << (ostream& os, vector& vec) { for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : " "); } return os; } #pragma endregion #pragma region Functions #pragma endregion signed main() { INIT; // 必須 int a, b, c, d, e; cin >> a >> b >> c >> d >> e; int sum{ 0 }; vector sums; rep(i, b-c) { if (i == 0) { sums.push_back( d*a); continue; } // i >= 1 if (i % 10 != 0) sums.push_back(sums[i - 1] * a); else if (i % 10 == 0 and e <= sums[i - 1]) sums.push_back((sums[i - 1] - e) * a); else if (i % 10 == 0 and e > sums[i - 1]) sums.push_back(sums[i - 1] * a); } sum = accumulate(ALL(sums), 0); cout << sum << "\n"; }