• [luoguP2626] 斐波那契数列(升级版)(模拟)


    传送门

    模拟

    代码

    #include <cmath>
    #include <cstdio>
    #include <iostream>
    #define N 50
    #define M 1000001
    #define LL long long
    
    int n, m;
    LL f[N], a[M], p[M];
    bool b;
    
    inline int read()
    {
    	int x = 0, f = 1;
    	char ch = getchar();
    	for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    	for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
    	return x * f;
    }
    
    int main()
    {
    	int i;
    	n = read();
    	f[1] = 1;
    	for(i = 2; i <= n; i++) f[i] = (f[i - 1] + f[i - 2]) % (1 << 31);
    	if(f[n] == 1)
    	{
    		printf("%lld=%lld", f[n], f[n]);
    		return 0;
    	}
    	m = sqrt(f[n]);
    	printf("%lld=", f[n]);
    	for(i = 2; i <= m; i++)
    		while(!(f[n] % i))
    		{
    			if(!b) printf("%d", i), b = 1;
    			else printf("*%d", i);
    			f[n] /= i;
    		}
    	if(b && f[n] > 1) printf("*%lld", f[n]);
    	else if(!b && f[n] > 1) printf("%lld", f[n]);
    	return 0;
    }
    

      

  • 相关阅读:
    JS中return函数
    Java异常
    ssh框架整合之注解版
    ssh框架整合之xml版
    Struts之拦截器
    Struts入门初体验
    Hibernate关联查询 一对多双向关联
    Hibernate之hql
    Aop小列子
    深入.Net第二章总结
  • 原文地址:https://www.cnblogs.com/zhenghaotian/p/7078869.html
Copyright © 2020-2023  润新知