B Icebound and Sequence
这道题目用到快速幂+二分乘法
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 3005;
const int mod = 1000007;
ll multi(ll a,ll b,ll m){
ll ans = 0;
a %= m;
while(b){
if(b & 1){
ans = (ans + a) % m;
b--;
}
b >>= 1;
a = (a + a) % m;
}
return ans;
}
ll quick_pow(ll a,ll b,ll mod){
ll res = 1;
while(b){
if(b % 2 == 1)
res = multi(res, a, mod);
b >>= 1;
a = multi(a, a, mod);
}
return res;
}
int main() {
int T;
scanf("%d", &T);
while(T--) {
ll q, n, p;
scanf("%lld %lld %lld", &q, &n, &p);
ll sum = 0, t;
t = quick_pow(q, n + 1, p * (q - 1)) - q;
sum = t / (q - 1);
printf("%lld\n", sum);
}
return 0;
}
G 点我
别完了特判0的情况
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 3005;
const int mod = 1000007;
int main() {
int n;
scanf("%d", &n);
if(n == 0) {
printf("qiandaoshibai\n");
return 0;
}
if(n % 2) printf("qiandaoshibai\n");
else printf("qiandaochenggong\n");
return 0;
}
H 天神的密码
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 3005;
const int mod = 1000007;
int getSum(ll x) {
int sum = 0;
while(x) {
sum += x % 10;
x /= 10;
}
return sum;
}
int main() {
int T;
scanf("%d", &T);
while(T--) {
ll n, k;
scanf("%lld %lld", &n, &k);
ll x;
if(k == 2) x = n * n, x = getSum(x);
else x = n, x = getSum(x);
while(x / 10 != 0) {
x = getSum(x);
}
printf("%lld\n", x);
}
return 0;
}
K 河北美食
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 3005;
const int mod = 1000007;
struct node {
string st;
ll num;
};
node a[10005];
int cnt;
int main() {
int n, m;
string st;
ll num;
map<string, ll> mp;
scanf("%d %d", &n, &m);
for(int i = 0; i < n; ++i) {
cin >> a[i].st >> a[i].num;
mp[a[i].st] = a[i].num;
}
bool flag = true;
while(m--) {
int k;
scanf("%d", &k);
for(int i = 0; i < k; ++i) {
cin >> st >> num;
if(mp[st] < num) {
flag = false;
break;
} else {
mp[st] -= num;
}
}
}
if(flag == true) {
printf("YES\n");
map<string, ll>::iterator it;
for(int i = 0; i < n; ++i) {
for(it = mp.begin(); it != mp.end(); ++it) {
if(a[i].st == it->first && it->second != 0) {
cout << a[i].st << " " << it->second << endl;
}
}
}
} else {
printf("NO\n");
}
return 0;
}