Indialbedo's blog

By Indialbedo, history, 5 months ago, In English
$$$\sum_{i=1}^n\sin(ix)=\dfrac{\cos(x/2)-\cos((2n+1)x/2)}{2\sin(x/2)}$$$
$$$\sum_{i=1}^n\sin(ix)=\dfrac{\sin(\frac{n+1}2x)\sin(\frac n 2x)}{\sin(\frac x 2)}$$$

Now I give my proof.

notice that $$$\sin(x)\sin(y)=\frac{1}{2}(cos(x-y)-cos(x+y))$$$

$$$\sum_{i=1}^n\sin(ix)=\dfrac{\sin(x/2)(\sin(x)+\sin(2x)+\sin(3x)+\ldots)}{\sin(x/2)}$$$
$$$=\dfrac{\cos(x/2)-\cos(3x/2)+\cos(3x/2)-\cos(5x/2)\ldots+\cos((2n+1)x/2)}{2\sin(x/2)}$$$
$$$=\dfrac{\cos(x/2)-\cos((2n+1)x/2)}{2\sin(x/2)}$$$

inverse $$$\sin(x)\sin(y)=\frac{1}{2}(cos(x-y)-cos(x+y))$$$ to be $$$\cos(a)-\cos(b)=-2\sin(\frac{a+b}2)\sin(\frac{a-b}2)$$$

$$$\text{LHS}=\dfrac{\sin(\frac{n+1}2x)\sin(\frac n 2x)}{\sin(\frac x 2)}$$$

maybe a nice idea! What do u think?

Read more »

 
 
 
 
  • Vote: I like it
  • +61
  • Vote: I do not like it

By Indialbedo, history, 6 months ago, In English

have a look at this code of 1565E which got runtime error and idk why, so I have to write again in C++ during the competition.

I'll appreciate if somebudy could do me a favor :)

import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def rdvec():
  return [int(i) for i in input().split()]
def rd():
  return int(input())
T=int(input())
def solve():
  n=rd()
  g=[[] for i in range(n)]
  U=[0]*n
  for i in range(n-1):
    x,y=rdvec()
    x-=1
    y-=1
    g[x].append(y)
    g[y].append(x)
    U[x]+=1
    U[y]+=1
  def dfs(x,fa,s):
    if s%2==0:
      U[x]=-U[x]
    for y in g[x]:
      if y!=fa:
        dfs(y,x,s+1)
  dfs(0,0,0)
  print(*U)
for o in range(T):
  solve()

Read more »

 
 
 
 
  • Vote: I like it
  • +6
  • Vote: I do not like it