15 solutions

  • 0
    @ 2022-1-18 11:42:15

    运用了一个位运算异或来判断分解的奇偶,本人代码写的判断素数和分解有点重复;

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N =1e6+5;
    int check(ll x)
    {
    	if(x==1) return 0;
    	int i;
    	for(i=2;i*i<=x;i++)
    	{
    		if(x%i==0) break;
    	}
    	if(i*i>x) return 1;
    	return 0;
    }
    int main()
    {
    	ll n,pp=1;
    	cin>>n;
    	if(check(n)) cout<<n<<endl;
    	else{
    		for(int i=2;i*i<n;i++)
    		{
    			ll a=0;
    			while(n%i==0)
    			{
    				a^=i;
    				n/=i;
    			}
    			if(a) pp*=a;
    
    			if(check(n))
    			{
    				pp*=n;
    				break;
    			}
    		}
    		cout<<pp<<endl;
    	}	
    	return 0;
    }
    

    Information

    ID
    189
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    8
    Tags
    # Submissions
    493
    Accepted
    91
    Uploaded By