3 solutions

  • 2
    @ 2025-5-28 18:54:17
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int n;
    	cin>>n;
    	int t=2;
    	int cnt=0; //当前是第几个因数
    	cout<<n<<"=";
    	for(int i=2;i<=n/i;i++)
    	{
    		while(n%i==0)
    		{
    			cnt++; //多了一个因数
    			if(cnt>1)
    			{
    				cout<<"*";	
    			} 
    			cout<<i;
    			n/=i;
    				
    		} 
    	} 
    	if(n>1) //说明剩余的n本身是一个质数 
    	{
    		cout<<"*"<<n;
    	}
    	return 0;
    }
    
    
    • 0
      @ 2024-11-30 11:23:19
      #include<bits/stdc++.h>
      using namespace std;
      int main()
      {
          int n;
          cin>>n;
          cout<<n<<"=";
          int i=2;
          while(n!=1)
          {
              bool temp=true;
              while(temp)
              {
                  if(n%i==0)
                  {
                      cout<<i;
                      n/=i;
                      if(n!=1) cout<<"*";
                  }
                  else temp=false;
              }
              i++;
          }
      }
      
      • -3
        @ 2024-11-4 18:50:41
        #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
            int n;
            cin>>n;
            cout<<n<<"=";
            int t = n;
            int i = 2;
            while(n != 1)
            {
                while(n % i == 0)
                {
                    if(t != n) cout<<"*";
                    cout<<i;
                    n /= i;
                }
                i++;
            }
            return 0;
        }
        
        • 1

        Information

        ID
        56
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        3
        Tags
        (None)
        # Submissions
        207
        Accepted
        59
        Uploaded By