3个点超时
查看原帖
3个点超时
1044970
LucAlva楼主2024/1/14 11:25
#include <bits/stdc++.h>
using namespace std;
bool aaa(int i){
    for(int j=2;j<=sqrt(i);j++){
        if(i%j==0) return 0;   
    }
    return 1;
}
struct ccc{
    long long v;
    long long t;
};
int main(){
    long long a,c=0;
    cin>>a;
    int z=sqrt(a)+1;
    ccc b[z]{};
    if(a%2==0){
		c++;
		long long s=0;
		while(a%2==0){
		s++;
		a/=2;
		}
		b[c].t=s;
		b[c].v=2;
	}
    for(long long i=3;i<=a;i+=2){
        if(a%i==0){
            if(aaa(i)==1){
                c++;
                long long s=0;
                while(a%i==0){
					s++;
					a/=i;
				}
				b[c].t=s;
				b[c].v=i;
            }
        }
    }
    cout<<b[1].v;
    if(b[1].t!=1){
        cout<<'^'<<b[1].t;
    }
    for(int i=2;i<=c;i++){
        cout<<" * "<<b[i].v;
        if(b[i].t!=1){
            cout<<'^'<<b[i].t;
        }
    }
    return 0;
}

对了,为什么这几个会紫啊

#include <bits/stdc++.h>
using namespace std;
bool aaa(int i){
    for(int j=2;j<=sqrt(i);j++){
        if(i%j==0) return 0;   
    }
    return 1;
}
int bbb(long long i,long long &a){
	long long s=1;
    if(a%i!=0) return s;
    else{
    	a/=i;
		return bbb(i,a);
	}
}
struct ccc{
    long long v;
    int t;
};
int main(){
    long long a,c=0;
    cin>>a;
    ccc b[a+1]{};
    for(long long i=2;i<=a;i++){
        if(a%i==0){
            if(aaa(i)==1){
                c++;
                b[c].t=bbb(i,a);
                b[c].v=i;
            }
        }
    }
    cout<<b[1].v;
    if(b[1].t!=1){
        cout<<'^'<<b[1].t;
    }
    for(int i=2;i<=c;i++){
        cout<<" * "<<b[i].v;
        if(b[i].t!=1){
            cout<<'^'<<b[i].t;
        }
    }
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
struct ccc{
    long long v;
    long long t;
};
int main(){
    long long a,c=0,e=0;
    cin>>a;
    long long b[a+1]{},d[a+1]{};
    for(long long i=2;i<=a;i++){
		if(b[i]==0){
			c++;
			d[c]=i;
			for(long long j=i*2;j<=a;j+=i){
				b[j]=1;
			}
		}
	}
    for(long long i=1;i<=c;i++){
		if(a%d[i]==0){
			long long s=0;
			while(a%d[i]==0){
				a/=d[i];
				s++;
			}
			if(e==0) e=1;
			else{
				cout<<" * ";
			}
			cout<<d[i];
			if(s!=1){
				cout<<'^'<<s;
			}
		}
	}
    return 0;
}
2024/1/14 11:25
加载中...