POJ1183 反正切函数的应用 数学 C语言

题目:http://poj.org/problem?id=1183

思路:知道要推导公式,根据公式(4)的两种形式推来推去,似乎没有太大结果。看了Discuss里大牛的推导,看懂之后就很简单了,关键就是b = a+m, c = a+n .

借用大牛的推导…… 

1/a = (1/b + 1/c)/ (1 - 1/(b*c)) => bc-1 = a(b+c) assume b=a+m and c=a+n (b and c is always bigger than a) (a+m)(a+n)-1=a(a+m+a+n) => a*a+a*n+a*m+m*n-1=2*a*a+m*a+n*a => m*n=a*a+1 and then for(m=a;m>=1;m--) if((a*a+1)%m==0) break; n=(a*a+1)/m
提交情况: WA 1次, AC 1次
总结:看a的范围觉得int足够了,结果WA。为了保险起见以后还都是用I64吧
 
AC code:
ContractedBlock.gif ExpandedBlockStart.gif View Code
 1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #define I64 __int64
6
7 int main() {
8 I64 a;
9 scanf("%I64d", &a);
10 I64 m, n;
11 for(I64 i = a; ; --i) {
12 if(!((a * a + 1) % i)) {
13 m = i;
14 n = (a * a + 1) / m;
15 break;
16 }
17 }
18 printf("%I64d\n", 2 * a + m + n);
19 return 0;
20 }

转载于:https://www.cnblogs.com/cloehui/archive/2011/07/24/2115488.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值