Test instructions: To give a number, to find the largest factor, the factor is also to meet the number of squares can not be his factor.
My solution is almost violent, and it should be possible to find a mathematical method of non-violence (or less "violence").
My solution is:
#include <cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<cmath>#include<Set>using namespacestd;#defineMAX (x, Y) (((x) > (y))? (x): (y))#defineMIN (x, Y) ((() < (y))? (x): (y))#defineABS (x) ((x) >0? ( x):-(x))Const Long LongINF =0x7fffffff;Const Long Longn=1000000+Ten;Long LongA[n];BOOLCheckLong Longx) { for(Long LongI=2; i*i<=x; i++){ if(x% (i*i) = =0){ return 0; } } return 1;}intMain () {Long LongN; CIN>>N; Long Longp=0; for(Long LongI=1; i*i<=n; i++){//cout<<i<<endl; if(n%i = =0) {a[p++]=i; A[p++]=n/i; }} sort (A,a+p); for(Long Longi=p-1; i>=0; i--){ if(check (A[i])) {printf ("%i64d\n", A[i]); Break; } }View Code
Later on the online study of the decomposition of mass factor solution. The idea is to start from 2, a test factor, and the N in the I-factor extraction from dry, to n==1 or i*i>n.
Code
#include <iostream>using namespacestd;intMain () {Long LongN; CIN>>N; Long Longans=1; for(Long LongI=2; i*i<=n; i++){ if(n==1) Break; if(n%i = =0) ans*=i; while(n%i = =0) {n/=i; }} cout<<ans*n<<Endl; return 0;}View Code
Essays-Pre-invitational-codeforces 588B