zoukankan      html  css  js  c++  java
  • A1096 Consecutive Factors [因子分解]

    在这里插入图片描述

    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<string>
    #include<time.h>
    #include<math.h>
    using namespace std;
    typedef long long ll;
    int main()
    {
    	int n; cin >> n;
    	int sqr = sqrt(n), length = 0, k = 0;
    	if (n >= 4)
    	{
    		for (int i = 2; i <= sqr; i++)
    		{
    			int temp = 1, j = i;
    			while (1)
    			{
    				temp *= j;
    				if (n % temp != 0) break;
    				if (j - i + 1 > length)
    				{
    					k = i;
    					length = j - i + 1;
    				}
    				j++;
    			}
    		}
    	}
    	else
    	{
    		for (int i = 2; i <= n; i++)
    		{
    			int temp = 1, j = i;
    			while (1)
    			{
    				temp *= j;
    				if (n % temp != 0) break;
    				if (j - i + 1 > length)
    				{
    					k = i;
    					length = j - i + 1;
    				}
    				j++;
    			}
    		}
    	}
    	if (length == 0) //质数
    	{
    		cout << "1" << endl;
    		cout << n << endl;
    	}
    	else
    	{
    		cout << length << endl;
    		for (int i = 0; i < length; i++)
    		{
    			cout << k+i;
    			if (i < length - 1)
    				cout << "*";
    		}
    	}
    }
    
  • 相关阅读:
    make menuconfig出现乱码
    内存中的变量和值
    is&==
    python小整数池
    生成器
    GIL
    grub rescue问题修复
    期末考试
    期末要求
    选课练习
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13812042.html
Copyright © 2011-2022 走看看