4 solutions

  • 0
    @ 2022-3-16 19:54:41
    #include<iostream>
    
    
    using namespace std;
    const int N = 1e6 + 5;
    bool flag[N];
    
    int main(void)
    {
    	int j, k;
    
    
    	cin >> j >> k;
    	int d = j * k / __gcd(j, k);
    
    	for (int i = 0; i < d; i++)//关于i和取的边界不用纠结
    	{
    		for (int t = 0; t < d; t++)
    		{
    			if (i * j + k * t > d) break;
    			flag[i * j + k * t] = 1;
    		}
    	}
    
    	for (int i = d; i > 0; i--)//从后向前遍历找到第一个false即所求
    	{
    		if (!flag[i])
    		{
    			cout << i << endl;
    			break;
    		}
    
    	}
    
    
    	return 0;
    }
    

    Information

    ID
    1588
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    3
    Tags
    # Submissions
    43
    Accepted
    25
    Uploaded By