題目鏈接
題目描述
After successfully conquering the South Pole, Davor is preparing for new challenges. Next up is the Arctic expedition to Siberia, Greenland and Norway. He begins his travels on 31 December 2018, and needs to collect ?N kunas (Croatian currency) by then. In order to do this, he has decided to put away ?X (?X ≤ 100) kunas every Monday to his travel fund, ?X + K kunas every Tuesday, ?X + 2* ?K every Wednesday, and so on until Sunday, when he will put away ?X + 6* ?K kunas. This way, he will collect money for 52 weeks, starting with 1 January 2018 (Monday) until 30 December 2018 (Sunday).
If we know the amount of money ?N?, output the values ?X and ?K so that it is possible to collect the ?exact money amount in the given timespan. The solution will always exist, and if there are multiple, output the one with the greatest ?X ? and smallest ?K ?.
輸入格式
The first line of input contains the integer ?N? (1456 ≤ ?N? ≤ 145600), the number from the task.
輸出格式
The first line of output must contain the value of ?X (?0 < ?X ?≤ 100 ?)?, and the second the value of K (K ?> 0 ?)?.
題意翻譯
在征服南極之后,Davor 開始了一項新的挑戰,下一步是在西伯利亞、格林蘭、挪威的北極圈遠征,他將在 2018 年 12 月 31 日開始出發,在這之前需要一共籌集 n 元錢,他打算在每個星期一籌集 x 元,星期二籌集 x+k 元,……,星期日籌集 x+6k 元,并在 52 個星期內籌集完,其中 x,k 為正整數,并且滿足 1≤x≤100,
現在請你幫忙計算 x,k 為多少時,能剛好籌集 n 元,
如果有多個答案,輸出 x 盡可能大,k 盡可能小的,注意 k 必須大于 0,
輸入輸出樣例
輸入 #1
1456
輸出 #1
1
1
輸入 #2
6188
輸出 #2
14
1
輸入 #3
40404
輸出 #3
99
4
代碼:
#include<iostream>
using namespace std;
int main()
{
int n, count = 0;
cin >> n;
n /= 364;
for(int i = 1; 3 * i + 1 <= n; i++) //x
{
for(int j = 1; 3 * i + j <= n && j <= 100; j++) //k
{
if(3 * i + j == n)
{
cout << j << endl << i << endl;
count = 1;
break;
}
}
if(count == 1) break;
}
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/262200.html
標籤:其他
上一篇:C++: 指標空值nullptr
