1 solutions

  • 0
    @ 2022-3-30 19:03:10
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    #include<vector>
    #include<string>
    #include<map>
    #include <climits>
    
    using namespace std;
    
    const int N = 1e5 + 5;
    bool isprime[N];
    int prime[100005];
    int c;
    void oula(int a, int b)//欧拉素数筛筛出素数存到数组里面去
    {
    	a = 2;
    	for (int i = a;i <= b; i++)
    	{
    		if (!isprime[i]) prime[++c] = i;
    		for (int j = 1; j <= c && i * prime[j] <= b; j++)
    		{
    			isprime[i * prime[j]] = true;
    			if (i % prime[j] == 0) break;
    		}
    	}
    }
    
    int main(void)
    {
    	int a, b;
    	cin >> a >> b;
    
    	oula(a, b);
    	for(int i=a;i<=b;i++)
    	{
    		if (!isprime[i]) cout << i << "=" << i<<endl;
    		else {
    			cout << i << "=";
    			int k = i;
    			for (int t = 1; t <= c; t++)
    			{
    				if (k % prime[t] == 0)
    				{
    					if (k / prime[t] != 1) cout << prime[t] << "*";
    					else
    					{
    						cout << prime[t];
    						cout << endl;
    					}
    					k /= prime[t];
    					t--;//4=2*2的情况
    				}
    			}
    		}
    	}
    	return 0;
    }
    
    • 1

    Information

    ID
    1174
    Time
    1000ms
    Memory
    512MiB
    Difficulty
    7
    Tags
    # Submissions
    17
    Accepted
    9
    Uploaded By