Luogu brush questions C++ language | P4956 Davor

Learn C++ from a baby! Record the questions in the process of Luogu C++ learning and test preparation, and record every moment.

Attached is a summary post: Luogu Brush Questions C++ Language | Summary


【Description】

After conquering the Antarctic, Davor embarked on a new challenge. The next step is Arctic Circle expeditions in Siberia, Greenland, Norway. He will start to set off on December 31, 2018, and needs to raise a total of  n  yuan before that. He intends to raise $x every Monday   , $  x + k on Tuesday  , ...,  and $ x +6k on Sunday  for 52 consecutive weeks. Where  x and k  are positive integers and satisfy 1≤x≤100 .

Now please help me to calculate  x and k  , so that I can just raise  n  yuan.

If there are multiple answers, output  x  as large as possible and k  as small as possible. Note that  k  must be greater than 0.

【enter】

The first line of input contains the integer N (1456 ≤ N ≤ 145600), the number from the task.

【Output】

The first line of output must contain the value of X (0 < X ≤ 100 ), and the second the value of K (K > 0 ).

【Input sample】

1456

【Example of output】

1

1

【Code Explanation】

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,x,k,ans;
    cin >> n;
    // //方法一:数学方法计算
    // n /= 52;
    // n /= 7;  //n = x + 3k
    // x = n - 3;
    // if (x>100) x = 100;
    // for (int i=x; i>=0; i--) {
    //     if ((n-i)%3==0) {
    //         cout << i << endl << (n-i)/3;
    //         break;
    //     }
    // }
    //方法二
    n /= 52;
    for (x=100; x>=0; x--) {
        if ((n-x*7)%21==0 && (n-x*7)>0) {
            cout << x << endl << (n-x*7)/21;
            break;
        }
    }
    return 0;
}

【operation result】

1456
1
1

Guess you like

Origin blog.csdn.net/guolianggsta/article/details/132642279