学習は、上流を漕ぎのようなものです
猿の戦い
タイトル説明
スタート林のみ、互いに少し猿を知って、彼らはしばしば戦うが、戦いは良い友人の両方であってはなりませんNがあります。各フレームが終了した後、双方は戦う、とその友人はお互いを知っているし、良い友達になります。N-1回の戦いの後、森全体の猿は良い友達になります。
質問は今、戦いが処理どのように多くの異なるの合計です。
例えば、N = 3、そこ{} {1-2、1-3 1-2 2-3 1-3 2-3} {} {} {1-3,1-2 2-3 2-3,1-3} {1-2}六つの異なる戦闘方法。
エントリー
整数N.
輸出
ライン、プログラム番号は9999991を国防省。
サンプル入力
4
サンプル出力
96
ヒント
データN <= 10の50%。3。
100%のデータN <= 10 。6。
トピックのアイデア
この問題は、知識点を必要とするPurfer列の数である
栗の画像は、方法によってルートに接続されたN-1のセットの残りの点です。
N-合計N-2-ケース。
これのルートを決定するので、その後のn-1の残りの部分は、(N-1)があります!順列の方法
、それは、答えが(N - 1)である* N-!N 2 -
通常のアナログ動作によりアウトすることができます
交流コードは以下の通りです
#include<algorithm>
#include<iostream>
#include<string.h>
#include<utility>
#include<stdio.h>
#include<vector>
#include <stack>
#include<string>
#include<math.h>
#include<cmath>
#include<queue>
#include<map>
#pragma warning(disable:4244)
#define PI 3.1415926536
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll ll_inf = 9223372036854775807;
const int int_inf = 2147483647;
const short short_inf = 32767;
const char char_inf = 127;
inline ll read() {
ll c = getchar(), Nig = 1, x = 0;
while (!isdigit(c) && c != '-')c = getchar();
if (c == '-')Nig = -1, c = getchar();
while (isdigit(c))x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar();
return Nig * x;
}
inline void out(ll a)
{
if (a < 0)putchar('-'), a = -a;
if (a >= 10)out(a / 10);
putchar(a % 10 + '0');
}
ll qpow(ll x, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)res = (res * x) % mod;
x = (x * x) % mod; n >>= 1;
}
return res;
}
#define read read()
ll ans = 0;
int main()
{
ll n = read;
ans = qpow(n, n - 2, 9999991);
for (int i = 1; i < n; i++)
{
ans *= i;
ans %= 9999991;
}
cout << ans << endl;
return 0;
}
ボートのための苦いトラックの道路グラウンド、無限の学習があります。