5 条题解

  • 6
    @ 2022-12-12 10:11:11
    #include <iostream>
    using namespace std;
    int main()
    {
        int n;
        cin >> n;
        while (!(n % 2))
        {
            cout << 2 << " ";
            n /= 2;
        }
        for (int i = 3; i <= n; i += 2)
        {
            while (!(n % i))
            {
                cout << i << " ";
                n /= i;
            }
        }
        return 0;
    }
    
    • 3
      @ 2023-12-2 23:08:11
      #include <bits/stdc++.h>
      using namespace std;
      int n;
      int main()
      {
          cin>>n;
          for(int i=2;i*i<=n;i++)
              while(n%i==0){
                  cout<<i<<" ";
                  n/=i;
              }
          if(n!=1) cout<<n;
          return 0;
      }
      

      记得点赞!

      • 2
        @ 2023-10-3 21:21:07
        #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
            int n,i=2;
            cin>>n;
            while(n!=1)
            {
                if(n%i==0)
                {
                    cout<<i<<" ";
                    n/=i;
                    
                }
                else
                {
                    i++;
                }
            }
            return 0;
        }
        
        • 1
          @ 2023-1-16 10:25:39
          #include<bits/stdc++.h>
          using namespace std;
          int main()
          {
          	int n;
          	cin >> n;
          	int i = 2;
          	while(n != 1){
          		if(n%i == 0){
          			cout << i << " ";
          			n /= i;
          		}
          		else {
          			i++;
          		}
          	}
          	return 0;
          }
          
          
          
          • -1
            @ 2023-4-15 9:44:26

            真正的标准做法()

            #include<bits/stdc++.h>
            using namespace std;
            int n,p[100],x;
            bool prime(int xx)
            {
                for (int i=2;i*i<=xx;i++)
                    if (xx%i==0)
                        return 0;
                return 1;
            }
            int main()
            {
                cin>>n;
                for (int i=2;i<=1000;i++)
                    if (prime(i))
                    {
                        p[++x]=i;
                    }
                while (n>1)
                    for (int i=1;i<=x;i++)
                        if (n%p[i]==0)
                        {
                            cout<<p[i]<<" ";
                            n/=p[i];
                            break;
                        }
                return 0;
            }
            • 1

            【入门】任意输入一正整数N,要求把它拆成质因子的乘积。

            信息

            ID
            234
            时间
            1000ms
            内存
            16MiB
            难度
            3
            标签
            递交数
            130
            已通过
            71
            上传者