70pts TLE O(sprt(n))
查看原帖
70pts TLE O(sprt(n))
1152025
MATAIN楼主2024/9/28 10:59

求助

1.20s(其他点4ms)

#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    ll n,tmp,first=1;
    cin>>n;
    for(int i=2;i*i<=n;i++)
    {
    	tmp=0;
    	while(n%i==0)
    	{
    		tmp++;
    		n/=i;
		}
		if(first==0&&tmp) cout<<" "<<"*"<<" ";
		if(tmp==1) cout<<i;
		if(tmp>1) cout<<i<<"^"<<tmp;
		if(tmp) first=0;
	}
	if(n!=1)
	{
		if(first==0) cout<<" "<<"*"<<" "<<n;
		else cout<<n;
	}

    return 0;
}
2024/9/28 10:59
加载中...