标签:style blog color 使用 os width
| input | output |
|---|---|
14 |
2 4 |
这里使用的数学思维:分解两个因子的思想,利用程序特点循环求解
发现自己的数学水平还是不行,要继续修补。-- 这些数学思想其实早就学过的,不过使用的不多,故此容易忘记。
N = A + (A + 1) + … + (A + P ? 1) 求出公式:N=(A+A+p-1)*p/2;
2*N=P*(2A+P-1) 然后是分解因子得到:x=P; y=(2A+P-1)
2*N=x*y
然后循环x,即p,求得符合条件的A就结束循环。
自己推导下,就明白啦。
void SumofSequentialNumbers1120()
{
long long S = 0;
cin>>S;
S <<= 1;
for (int p = (int)sqrtl(S); p >= 0 ; p--)
{
if (S % p == 0)
{
int y = int(S / p);
int a = y + 1 - p;
if (a % 2 == 0)
{
cout<<a/2<<‘ ‘<<p;
break;
}
}
}
}Timus 1120. Sum of Sequential Numbers 数学题,码迷,mamicode.com
Timus 1120. Sum of Sequential Numbers 数学题
标签:style blog color 使用 os width
原文地址:http://blog.csdn.net/kenden23/article/details/24598109