https://www.acmicpc.net/step/61
- (2023.07.12) -
C++
※ Note
- All the codes of any language for the same problem have basically the same result.
- Typical headers like the below are basically skipped, but they are noted seperately when theere are any additional line.
· C++ : #include <iostream> #define endl '\n'; using namespace std;
520Answer : C++ (2023.07.12)
int main()
{
// Input
int n;
cin >> n;
// Output
int ans = n * n - n; // do not need to use combination
cout << ans << endl;
return 0;
}맞았습니다!!
24Answer : C++ (2023.07.12)
int main()
{
// Input
int n;
cin >> n;
// Operate
int ans = 1;
while (n--) ans *= 2;
// Output
cout << ans << endl;
return 0;
}맞았습니다!!
103628800Answer : C++ (2021.07.26)
int factorial(int n)
{
if (n <= 1) return 1;
return n * factorial(n - 1);
}int main()
{
int N;
cin >> N;
cout << factorial(N) << endl;
return 0;
}맞았습니다!!
5 210Answer : C++ (2023.07.12)
int main()
{
// Input
int n, k;
cin >> n >> k;
// Operate
int ans = 1;
int k2 = k;
for (int i = 0; i < k; i++) ans *= n--;
for (int i = 0; i < k2; i++) ans /= k--;
// Output
cout << ans << endl;
return 0;
}맞았습니다!!
3
2 2
1 5
13 291
5
67863915Answer : C++ (2023.07.12)
int main()
{
int t;
cin >> t;
for (int i = 0; i < t; i++)
{
// Input
int n, m;
cin >> n >> m;
// Operate : mCn
long long ans = 1;
for (int j = 1; j <= n; j++) // j must start from 1, not 0
{
ans *= m--;
ans /= j;
}
// Output
cout << ans << endl;
}
return 0;
}맞았습니다!!