나의 발자취
8393. 팩토리얼 계산 (풀이 두개, 메모리 비교) 본문
#include <iostream>
using namespace std;
int main(){
int a;
cin >> a;
cout << (a*(a+1))/2 << endl;
}
factorial같은 전체합은 공식을 이용. (for문썼더니 오류..)
#include <iostream>
using namespace std;
int main(){
int a;
int b = 0;
cin >> a;
for (int i = 0; i <=a; i++)
b += i;
cout <<b << endl;
}
for문을 썼을 경우 메모리는 4KB 더 소모된다.
'computer language > C++' 카테고리의 다른 글
[2562]최댓값 (0) | 2020.11.18 |
---|---|
[10818] 최소, 최대 (0) | 2020.11.18 |
백준 1330. 시계 (0) | 2020.10.07 |
백준 1008 - A/B 출력 (0) | 2020.10.07 |
백준 11021번 (0) | 2020.09.14 |
Comments