题目要求
P1720题目链接
这个题纯粹在鬼扯,数学基础OK的人一眼就看得出是斐波那契数列。
求Fn其实是程设基础水平的题,千万别写递归——O((5/3)^n),真的慢~~
这破题为啥还WA我也不想啊,看着Fib,我心中的警惕心就起来了,想着int不一定稳,就用long把题AC了,但是我换成int测了一下48(题示边界值),结果是非负的,看起来是OK的:
我就用int交了一次,错了最后一个测试用例:
回测一下47:
不深究原因,显然溢出,爆了int,那就只能long咯,这破题,不至于BigInteger……
AC代码(Java语言描述)很简洁:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
scanner.close();
long num1 = 1, num2 = 1, result = 0;
for (int i = 3; i
关注
打赏
热门博文
- 【Linux】Ubuntu20.04安装和卸载MySQL8
- 【Linux】Ubuntu 20.04 报错 curl: (23) Failure writing output to destination 的解决方法
- 【Java】JUnit 4.13.2 警告 ‘assertEquals(double, double)‘ is deprecated 的解决方法
- 【JavaScript】处理 @parcel/transformer-js: Browser scripts cannot have imports or exports.
- 【Python】处理TypeError: Plain typing.NoReturn is not valid as type argument
- 【Python】Matplotlib可视化50例
- 【C语言】C语言修改MySQL数据库
- 【Java】从默认包导入类和对象报错的解决方法
- 【Java】panel.getGraphics()报错空指针异常的解决方法
- 【Java】IDEA编译Java项目报错 java: 找不到符号 的解决方法