今天是ACM赛!
我真是太菜了!
A - 10^N+7
You are given three non-negative integers, x, y, z. Your task is to find the smallest non-negative integer n with all of the following conditions:
· n mod 17=x
· n mod 107=y
· n mod 1000000007(=109+7)=z
这是一道签到题
用条件三枚举 n 的取值,判断是否符合前两个条件就行了
#include <bits/stdc++.h>
using namespace std;
const long long a = 17, b = 107, c = 1e9 + 7;
int main()
{
long long n, i = 0;
long long x, y, z;
cin >> x >> y >> z;
while (1)
{
n = i * c + z;
if (n % a == x && n % b == y)
{
cout << n << endl;
return 0;
}
i++;
}
return 0;
}
B - Coins
There are 1-, 5-, 10-, 50-, 100-, 500- yen coins, and you have an infinite number of coins of each type.
For a given positive integer x, let f(x) be the smallest number of coins you have to use to pay exactly x yen. For example, f(2018)=9 because 2018=1+1+1+5+10+500+500+500+500.
You are given a positive integer N. Count the number of positive integers x such that f(x)=N.
1≤N≤1018
这也是道签到题
我们可以想到 5 个 1 元可以用 1 个 5 元代替,2 个 5 元可以用 1 个 10 元代替
同理,50, 100 也可以想到
因为最