Considered separately k = 1 k = 2 and k> = 3 case
2 and 3 these two primes special encountered then a direct output line
For the "divine dissatisfaction about the number of m, the small m and a maximum ratio that" this description refers to itself and 1 m in addition to these two because the yard to find that the biggest
Can be found sqrt (m), 2 pairs always occurs according to the factor (except sqrt (m)), so finding a factor i will be the smallest m / i as the largest factor
If a prime number, an output
Type n and k
When k = 1, only once all tribute, go directly to the process described above
when k = 2, if the number is an even number, can "sum of two primes and even always split into" Output 2 (2 and 3 have special considerations) The
If it is an odd number, it is determined whether it is a prime number, is the output 1, or to find less than n largest prime number p, then n can be divided into p and np two portions (since p maximum, so np as small as possible, the maximum factors also can be as small as possible)
k = 3, if the number is an even number, can "sum of two primes and even always split into" Output 2 (ibid.) The
However, if it is odd, it is determined whether it is a prime number, it is the output 1, otherwise n is split into n-2 and 2 in two parts, since 2 is a prime number, n-2 in this case, an odd number, it is determined n-2 is not a prime number, 2 is output, otherwise, n can be divided into three portions, and two n-3, n-3 as an even number, according to the "even always split into a sum of two prime numbers" direct output 3
1 #include<bits/stdc++.h> 2 using namespace std; 3 int findm(int in){ 4 int i,d=sqrt(in); 5 for(i=2;i<=d;i++) 6 if(in%i==0) 7 return in/i; 8 return 1; 9 } 10 bool isp(int in){ 11 int i,d=sqrt(in); 12 for(i=3;i<=d;i+=2) 13 if(in%i==0) 14 return false; 15 return true; 16 } 17 int main(){ 18 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 19 int T,n,m,k; 20 cin>>T; 21 while(T--){ 22 cin>>n>>k; 23 if(n==2||n==3) 24 cout<<1<<endl; 25 else{ 26 if(k==1) 27 cout<<findm(n)<<endl; 28 else if(k==2){ 29 if(n%2==1){ 30 if(isp(n)) 31 cout<<1<<endl; 32 else{ 33 m=n-2 ; 34 is the while (! ISP (m)) 35 M- = 2 ; // n-odd, odd-numbered 2 are prime numbers outside, so every other -2 36 COUT << findm (nm) + . 1 << endl; 37 [ } 38 is } 39 the else 40 COUT << 2 << endl; 41 is } 42 is the else IF (K> = . 3 ) { 43 is IF (n-% 2 == . 1 ) { 44 is IF(isp(n)) 45 cout<<1<<endl; 46 else{ 47 if(isp(n-2)) 48 cout<<2<<endl; 49 else 50 cout<<3<<endl; 51 } 52 } 53 else 54 cout<<2<<endl; 55 } 56 } 57 } 58 59 return 0; 60 }