Simple simulation
Integer decomposed into a continuous factors.
Input formats:
In a given input row positive integer N .
Output formats:
First, the number of the first output line of the longest continuous factors; in line 2, and then press the 因子1*因子2*……*因子k
format of the output of the minimum contiguous factor sequence, wherein the ascending order output factor, not including one.
Sample input:
630
Sample output:
3 5*6*7
Violence done, simply enumerate what, keep the maximum length
must be open ll wow!
Code:
1 #include <stdio.h>
2 #include <iostream>
3 #include <algorithm>
4 #include <string.h>
5 #include <queue>
6 #include <map>
7 #include <math.h>
8 #include <set>
9 #include <vector>
10 #include <stack>
11 #define ll long long
12 #define mod 998244353
13 const int maxn=2e5+5;
14 const int nowmi = 0x3f3f3f3f;
15 const int N=1000010;
16 using namespace std;
17
18 ll isprime(ll x)
19 {
20 if(x==1)
21 return 0;
22 for(ll i=2;i*i<=x;i++)
23 if(x%i==0)
24 return 0;
25 return 1;
26 }
27 int main(){
28
29 ll n;
30 CIN >> n-;
31 is IF (isPrime (n-))
32 {
33 is COUT << . 1 << endl << n-;
34 is return 0 ;
35 }
36 LL len = 0 , S, ANS; // maximum length, the product , continuous factors most front of a
37 [ for (LL I = 2 ; I * I <= n-; I ++ ) {
38 is IF (n-% I == 0 ) {
39 S = I;
40 LL J;
41 is for (J = + I . 1 ; J * J <= n-; J ++ ) {
42 s*=j;
43 if(n%s!=0)
44 break;
45 }
46 if(j-i>len){//更新长度
47 len=j-i;
48 ans=i;
49 }
50 }
51 }
52 cout<<len<<endl;
53 for(ll i=ans;i<=ans+len-1;i++){
54 if(i!=ans)
55 cout<<"*";
56 cout<<i;
57 }
58 return 0;
59 }