1 条题解

  • 5
    @ 2022-12-12 19:27:32

    基础版

    #include <iostream>
    using namespace std;
    int main()
    {
    	int n, x;
    	cin >> n;
    	for (int i = 1; i <= n; i++)
        {
    		x = 0;
    		for (int j = 2; j < i; j++)
            {
    			if (i % j == 0)
                {
    				x++;
    			}
            }
    		cout << x << endl;
    	}
        return 0;
    }
    

    加强版

    #include <bits/stdc++.h>
    using namespace std;
    int x(int a)
    {
    	int sum = 0;
    	for (int i = 2; i < a; i++)
    	{
    		if (a % i == 0)
    		{
    			sum++; 
    		} 	
    	}
    	return sum;
    }
    int main()
    {
    	int n;
    	cin >> n;
    	for (int i = 1; i <= n; i++)
    	{
    		if (i == 1)
    		{
    			cout << 0 << endl;
    		}
    		else
    		{
    			cout << x(i) << endl;
    		}
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    492
    时间
    1000ms
    内存
    128MiB
    难度
    1
    标签
    递交数
    105
    已通过
    69
    上传者