2 条题解

  • 0
    @ 2025-5-27 20:39:20
    #include <iostream>
    using namespace std;
    int main(){
    	cout << "6 its factors are 1, 2, 3" << endl;
    	cout << "28 its factors are 1, 2, 4, 7, 14" << endl;
    		cout << "496 its factors are 1, 2, 4, 8, 16, 31, 62, 124, 248" << endl;
    }
    
    • 0
      @ 2024-12-24 10:06:01

      C :

      #include <stdio.h>
      int main()
      {
      	int j, k, s, i, a[20], b;
      	for (j = 1;j <= 1000;j++ )
      	{
      		i = 0;
      		s = 0;
      		for (k = 1;k < j;k++)
      		{
      			if (0 == (j%k))
      				s = s + k;
      		}
      		if (s == j)
      		{
      			printf("%d its factors are ", j);
      			for (k = 1;k < j;k++ )
      			{
      				if (0 == (j%k))
      				{
      					a[i] = k;
      					i++;
      				}
      			}
      			for (b = 0;b < i;b++ )
      			{
      				if (b != (i-1))
      					printf("%d,", a[b]);
      				else if (6 == j)
      					printf("%d\n", a[b]);
      				else
      					printf("%d \n", a[b]);
      			}
      		}
      	}
      } 
      

      C++ :

      #include<iostream>
      using namespace std;
      int main()
      {
      	int t=0;
      	for (int i=6; i<=1000; i++)
      	{
      		int sum=0;
      		for (int j=1; j<=i/2; j++)
      			if (i%j==0) sum+=j;
      		if (i==sum)
      		{
      			t++;
      			cout<<i<<" its factors are "<<1;
      			for (int j=2; j<=i/2; j++)
      				if (i%j==0) cout<<","<<j;
      			if (t==1) cout<<endl;
      			else cout<<" "<<endl;
      		}
      	}
      	return 0;
      }
      
      • 1

      信息

      ID
      1772
      时间
      1000ms
      内存
      12MiB
      难度
      10
      标签
      递交数
      1
      已通过
      0
      上传者