Fibonacci Numbers-hdu3117

Fibonacci Numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1285    Accepted Submission(s): 543


Problem Description
The Fibonacci sequence is the sequence of numbers such that every element is equal to the sum of the two previous elements, except for the first two elements f0 and f1 which are respectively zero and one.

What is the numerical value of the nth Fibonacci number?
 


 

Input
For each test case, a line will contain an integer i between 0 and 10 8 inclusively, for which you must compute the ith Fibonacci number fi. Fibonacci numbers get large pretty quickly, so whenever the answer has more than 8 digits, output only the first and last 4 digits of the answer, separating the two parts with an ellipsis (“...”).

There is no special way to denote the end of the of the input, simply stop when the standard input terminates (after the EOF).
 


 

Sample Input
  
  
0 1 2 3 4 5 35 36 37 38 39 40 64 65
 


 

Sample Output
  
  
0 1 1 2 3 5 9227465 14930352 24157817 39088169 63245986 1023...4155 1061...7723 1716...7565

 

思路:

//1.后4位15000次循环一次
//2.前四位用数学公式推导可求
//3.前四位具体推导方法如下:

fib(n)= ([(1+√5)/2] n -[(1-√5)/2]n)√5

fib(n)= [(1+√5)/2] n /√5//当n很大的时候[(1-√5)/2]n)很小,可忽略

log10fib(n)=log10([(1+√5)/2]n/√5)

log10fib(n)=nlog10(1+√5)-nlog102-log10√5

例如log10fib(n)=3.123123

则  10log10fib(n)=103.123123

显然fib(n)=0.123123*1000

只需要求0.123123小数部分前4位即可

 

import java.util.Scanner;

public class Main{

	public static int arr[] = new int[1000000];
	public static int fib[] = new int[41];
	public static int T = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		arr[1] = arr[2] = 1;
		//测试后4位循环(15000循环一次)
		for(int i=3; i<1000000; i++) {
			arr[i] = (arr[i-1]+arr[i-2])%10000;
			if(arr[i]==arr[2] && arr[i-1]==arr[1]) {
				T = i-2;
				break;
			}
		}
		//fib的前40位
		fib[1] = fib[2] = 1;
		for(int i=3; i<41; i++) {
			fib[i] = fib[i-1]+fib[i-2];
		}
		while(sc.hasNextInt()) {
			int n = sc.nextInt();
			if(n<40) {
				System.out.println(fib[n]);
			} else {
				double ans;
				ans = -0.5*Math.log10(5)+n*Math.log10(1+Math.sqrt(5))-n*Math.log10(2);
				ans -= (int)(ans);
				ans = Math.pow(10, ans);
				while(ans < 1000) {
					ans *= 10;
				}
				System.out.print((int)ans+"...");
				String str = arr[n%T]+"";
				while(str.length()<4) {
					str = "0"+str;
				}
				System.out.println(str);
			}
		}
	}
}


 

 

内容概要:本文详细介绍了如何利用Simulink进行自动代码生成,在STM32平台上实现带57次谐波抑制功能的霍尔场定向控制(FOC)。首先,文章讲解了所需的软件环境准备,包括MATLAB/Simulink及其硬件支持包的安装。接着,阐述了构建永磁同步电机(PMSM)霍尔FOC控制模型的具体步骤,涵盖电机模型、坐标变换模块(如Clark和Park变换)、PI调节器、SVPWM模块以及用于抑制特定谐波的陷波器的设计。随后,描述了硬件目标配置、代码生成过程中的注意事项,以及生成后的C代码结构。此外,还讨论了霍尔传感器的位置估算、谐波补偿器的实现细节、ADC配置技巧、PWM死区时间和换相逻辑的优化。最后,分享了一些实用的工程集成经验,并推荐了几篇有助于深入了解相关技术和优化控制效果的研究论文。 适合人群:从事电机控制系统开发的技术人员,尤其是那些希望掌握基于Simulink的自动代码生成技术,以提高开发效率和控制精度的专业人士。 使用场景及目标:适用于需要精确控制永磁同步电机的应用场合,特别是在面对高次谐波干扰导致的电流波形失真问题时。通过采用文中提供的解决方案,可以显著改善系统的稳定性和性能,降低噪声水平,提升用户体验。 其他说明:文中不仅提供了详细的理论解释和技术指导,还包括了许多实践经验教训,如霍尔传感器处理、谐波抑制策略的选择、代码生成配置等方面的实际案例。这对于初学者来说是非常宝贵的参考资料。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值