笔试编程---快手实习题目

第一题 快速幂

#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;
}

  链接 来源于牛客网




 

posted @ 2018-04-20 22:17  聊寂园  阅读(197)  评论(0编辑  收藏  举报