第一题 快速幂
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL dfs(LL x, LL y, LL N)
{
if (y == 0)
return 1;
LL ret = dfs(x, y / 2, N);
if (y % 2 == 0)
return ret * ret % N;
return ret * ret * x % N;
}
int main()
{
LL x, y, N;
cin >> x >> y >> N;
cout << dfs(x, y, N) << endl;
return 0;
}
第二题二分查找
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x;
char c;
vector<int> arr;
while (true) {
scanf("%d", &x);
arr.push_back(x);
if (getchar() == ‘\n‘)
break;
}
scanf("%d", &x);
printf("%u\n", lower_bound(arr.begin(), arr.end(), x) - arr.begin());
return 0;
}
原文:https://www.cnblogs.com/gaochaochao/p/8893877.html