# 【Foreign】tty的方程math [数学]

## tty的方程math

Time Limit: 50 Sec  Memory Limit: 128 MB

## Description

给定n、m、k、p。

a+b+c=n, a^2+b^2+c^2=m, a^3+b^3+c^3=k。

求a^p+b^p+c^p。

输入n、m、k、p

以A/B形式表示答案。

5 7 11 4

27/1

## HINT

0<=n,m,k <=200<=p<=10

## Solution

 1 \begin {align}
2 &a^p+b^p+c^p\:\:①
3 \\
4 \\&(a+b+c)*(a^{p-1}+b^{p-1}+c^{p-1})\:\:②
5 \\=&a^{p}+b^{p}+c^{p}+ab^{p-1}+ac^{p-1}+ba^{p-1}+bc^{p-1}+ca^{p-1}+cb^{p-1}
6 \\
7 \\∴&①-②
8 \\=&-(ab^{p-1}+ac^{p-1}+ba^{p-1}+bc^{p-1}+ca^{p-1}+cb^{p-1})
9 \\
10 \\&(ab+bc+ac)*(a^{p-2}+b^{p-2}+c^{p-2})\:\:③
11 \\=&ba^{p-1}+ab^{p-1}+abc^{p-2}+bca^{p-2}+cb^{p-1}+bc^{p-1}+ca^{p-1}+acb^{p-1}+ac^{p-1}
12 \\
13 \\∴&①-②+③=
14 \\=&bca^{p-2}+acb^{p-2}+abc^{p-2}
15 \\=&abc(a^{p-3}+b^{p-3}+c^{p-3})\:\:④
16 \\
17 \\∴&①-②+③=④即①=②-③+④
18 \\
19 \\&那么现在问题就是如何求出(a+b+c),(ab+ac+bc),(abc)。
20 \\&首先题目给定了a+b+c=n,a^2+b^2+c^2=m,a^3+b^3+c^3=k，那么：
21 \\
22 \\1.&a+b+c=n
23 \\2.&(a+b+c)^2=a^2+b^2+c^2+2ab+2ac+2bc
24 \\&ab+ac+bc=\frac{n^2-m}2
25 \\3.&(a+b+c)^3=a^3+b^3+c^3+3a^2b+3ab^2+3a^2c+3ac^2+3b^2c+3bc^2+6abc.
26 \\&a^2b+ab^2+a^2c+ac^2+b^2c+bc^2=(ab+ac+bc)*(a+b+c)-3abc
27 \\&n^3=k+3* \frac{(n^2-m) * n}2-9abc+6abc
28 \\&abc=\frac{2*k+3n*(n^2-m)-2*n^3}{6}
29 \end {align}
math

## Code

 1 #include<iostream>
2 #include<string>
3 #include<algorithm>
4 #include<cstdio>
5 #include<cstring>
6 #include<cstdlib>
7 #include<cmath>
8 using namespace std;
9 typedef long long s64;
10
11 const int ONE = 1000005;
12 const int MOD = 1e9 + 7;
13
14 int get()
15 {
16         int res = 1, Q = 1; char c;
17         while( (c = getchar()) < 48 || c > 57)
18             if(c == '-') Q = -1;
19         if(Q) res = c - 48;
20         while( (c = getchar()) >= 48 && c <= 57)
21             res = res * 10 + c - 48;
22         return res * Q;
23 }
24
25 s64 gcd(s64 a, s64 b)
26 {
27         while(s64 r = a % b) {a = b; b = r;}
28         return b;
29 }
30
31 int n, m, k, p;
32 struct power
33 {
34         s64 fz, fm;
35 }Ans[ONE], A, B, C, now;
36
37 power Deal(power a, power b)
38 {
39         s64 fz = a.fz * b.fm + b.fz * a.fm, fm = a.fm * b.fm;
40         int p1 = fz > 0, p2 = fm > 0;
41         fz = abs(fz), fm = abs(fm);
42         s64 r = gcd(fz, fm);
43         return (power){p1 * fz / r, p2 * fm / r};
44 }
45
46 int main()
47 {
48         cin >> n >> m >> k >> p;
49         if(p == 0) {printf("3"); return 0;}
50         Ans[1] = (power){n, 1};
51         Ans[2] = (power){m, 1};
52         Ans[3] = (power){k, 1};
53
54         A = (power){n, 1};
55         B = (power){n * n - m, 2};
56         C = (power){2 * k + 3 * n * (n * n - m) - 2 * n * n * n, 6};
57
58         for(int i = 4; i <= p; i++)
59         {
60             power now = (power){A.fz * Ans[i-1].fz, A.fm * Ans[i-1].fm};
61             now = Deal(now, (power){C.fz * Ans[i-3].fz, C.fm * Ans[i-3].fm});
62             now = Deal(now, (power){-B.fz * Ans[i-2].fz, B.fm * Ans[i-2].fm});
63
64             Ans[i] = now;
65         }
66
67         printf("%d/%d", Ans[p].fz, Ans[p].fm);
68 }
View Code

posted @ 2017-12-02 15:22  BearChild  阅读(255)  评论(0编辑  收藏  举报