zoukankan      html  css  js  c++  java
  • A1096 Consecutive Factors (20分)(质数分解)

    一、技术总结

    1. 这里面主要有

    二、参考代码

    #include<iostream>
    #include<vector>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    typedef long long LL;
    //const  int maxn = 1000000000;
    //bool isPrime(int n){
    //	if(n <= 1) return false;
    //	int sqr = (int)sqrt(n);
    //	for(int i = 2; i <= sqr; i++){
    //		if(n % i == 0) return false; 
    //	}
    //	return true;
    //}
    //
    //int prime[maxn], pNum = 0;//prime用来存放所有素数 
    //bool p[maxn] = {0};//i如果为false表示为素数,如果为true表明不是素数 
    //void Find_Prime(){
    //	for(int i = 2; i < maxn; i++){
    //		if(p[i] == false){
    //			prime[pNum++] = i;
    //			for(int j = i + i; j < maxn; j += i){
    //				p[j] = true;
    //			}
    //		}
    //	}
    //}
    
    int main(){
    	LL n;
    	scanf("%lld", &n);
    	LL sqr = sqrt(n), ansI = 0, ansLen = 0;
    	for(LL i = 2; i <= sqr; i++){
    		LL temp = 1, j = i;
    		while(1){
    			temp *= j;
    			if(n % temp != 0) break;
    			if(j - i + 1 > ansLen){
    				ansLen = j - i + 1;
    				ansI = i;
    			}
    			j++;
    		}
    	}
    	if(ansLen == 0){
    		printf("1
    %lld", n);
    	}else{
    		printf("%lld
    ", ansLen);
    		for(LL i = 0; i < ansLen; i++){
    			printf("%lld", ansI + i);
    			if(i < ansLen - 1){
    				printf("*");
    			}
    		}
    	}
    	return 0;
    } 
    
  • 相关阅读:
    Linux基础命令(一)
    You've made choice
    protege推理
    字符编码
    第二次作业
    数据类型-集合set
    数据类型-元组&字典
    数据类型-列表
    数据类型-数值&字符串
    流程控制之for循环
  • 原文地址:https://www.cnblogs.com/tsruixi/p/13216560.html
Copyright © 2011-2022 走看看