|
|
back to boardC ++ Accepted with long long :) I accepted this problem using long long variables. I know that is not optiomal solution but very interesting and I want to share it !!! #include <iostream> using namespace std; typedef long long ll; const ll mod = 10000000000ll; void solve(int n) { ll s1 = 0, s2 = 0; for(int i = 1; i <= n; i ++) { // inc s2 = s2 + 1; s1 = s1 + s2 / mod; s2 = s2 % mod; //mult s2 *= i; s1 *= i; s1 = s1 + s2 / mod; s2 = s2 % mod; } // sub s2 -= n; if(s2 < 0) { s1 --; s2 += mod; } // print if(s1 > 0) { printf("%lld%010lld", s1, s2); } else { printf("%lld", s2); } } void test() { for(int n = 1; n <= 21; n ++) { cout << n << " "; solve(n); cout << endl; } } int main() { //test(); int n; cin >> n; solve(n); } Edited by author 11.12.2018 11:39 |
|
|