L1-006 连续因子 (20 分)
原题地址
题意:提上说的很清楚
思路:连续除就行
C++:
#include <vector>
#include<stdio.h>
#include<string.h>
#include <cstring>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <set>
#include<cstring>
#define ll long long
#define MODD 1000000007
#define pii pair<int,int>
#include<stdio.h>
#include<string.h>
//#define ll long long
using namespace std;
int main() {
ll n,nn,sum =0, mma=0,ma=0;
cin >>n;nn = n;
for(ll i =2 ;i<=sqrt(n)+1;i++){
ll j = i;
if(nn%j!=0)continue;
else {
while(nn%j==0){
nn/=j;
j++;
sum++;
}//cout<<i<<" "<<sum<<endl;
if(ma<sum){
ma =sum ;
mma = i;
} sum=0;nn = n;
}
}
if(ma==0){
cout<<1<<endl;
cout<<n<<endl;
}
else{
cout<<ma <<endl;
cout<<mma;
for(ll i =1;i<ma;i++){
cout<<"*"<<mma+i;
}cout<<endl;
}
}
Java:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// write your code here
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
long mma =0,sum =0 , ma = 0 ;
long nn = n;
for(long i =2;i<=Math.sqrt(n)+1;i++){
long j = i;
sum =0 ;
if(nn%i!=0)continue;
else{
while(nn%j==0){
nn/=j;
j++;
sum++;
}if(ma<sum){
ma = sum ;
mma = i;
}
sum =0 ;
nn = n;
}
}
if(ma==0){
System.out.println(1);
System.out.println(n);
}
else{
System.out.println(ma);
System.out.print(mma);
for(long i = 1;i<ma;i++){
System.out.print("*"+(mma+i));
}
}
}
}