Essays-Pre-invitational-codeforces 588B

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.