fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define endl "\n"
  4. #define TranHungss(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  5. using namespace std;
  6.  
  7. int main(){
  8. TranHungss();
  9. int n;
  10. scanf("%d", &n);
  11. long long sum = 0; // Lưu tổng các giai thừa
  12. for(int i = 1; i <= n; i++){
  13. long long giai_thua = 1; // Mỗi vòng lặp khởi tạo lại biến giai thừa
  14. for(int j = 1; j <= i; j++){
  15. giai_thua *= (long long)j; // Nhân j vào giai thừa j chạy từ 1 -> i
  16. }
  17. sum += giai_thua; // Sau khi tính xong giai thừa cộng vào biến sum
  18. }
  19. printf("%lld", sum);
  20. }
Success #stdin #stdout 0.01s 5292KB
stdin
3
stdout
9