Using inductive analysis, we can know that the dead loop is only 4.
Analyze the complexity, if n is large and not a prime number, the sum factor (n) ≥2+N/2≈N/2 can be known according to the basic inequality.
The complexity is O (t*logn*sqrt (N)), the upper bound is relatively loose. If you use Pollard_rho again to open a square estimate constant is also similar.
#include <bits/stdc++.h>using namespaceStd;typedefLong Longll;intDecompose (intXBOOL&is_pm) { intRe =0; for(inti =2; I*i <= x; i++){ while(x% i = =0) {Re+ = i; X/=i; }} is_pm= !re; if(X >1) {Re+=x; } returnre;}//#define LOCALintMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endif intx, y; BOOLis_pm; while(~SCANF ("%d", &x)) { if(x = =4) puts ("-1"); Else { while(true) {y=decompose (x, is_pm); if(IS_PM) Break; X=y; } printf ("%d\n", x); } } return 0;}
UESTC 1246 Demolition X3