A. Vasya and Socks(模拟,思维)
题目链接:codeforces 460A
题意:
Vasya有n双 袜子,每天穿一双袜子,然后扔掉,妈妈每隔 m给他送一双,问多少天后他没有袜子穿
题解:模拟
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin >> n >> m;
int ans = 0;
ans = n + (n-1)/ (m-1);
cout << ans << endl;
return 0;
}
B. Little Dima and Equation
题目链接:codeforces 460B
题意:
给出a, b, c, 求所有满足 x = b * s (x) ^ a + c的x值,其中s(x) 是数字x上所有位数字之和
题解:
根据x的范围确定 1 < s(x) <= 81, 所以求出x ,然后判断 x的各个位上的数字之和是否等于 s(x)
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll poww(ll p, ll u){
ll res = 1;
for(int i = 1; i <= u; i++){
res = res * p;
}
return res;
}
ll s(ll x){
ll res = 0;
while(x){
res += x % 10;
x = x / 10;
}
return res;
}
int main(){
ll a, b, c, k = 0;
int arr[10000];
cin >> a >> b >> c;
for(ll i = 1; i <= 81; i++){
ll x = b * poww(i, a) + c;
if(s(x) == i && x <= 1e9){
arr[k++] = x;
}
}
cout << k << endl;
for(int i = 0; i < k; i++){
cout << arr[i] << " ";
}
return 0;
}