4.13腾讯音乐笔试
全部评论
#include<iostream>
(30316)#include<vector>
using namespace std;
int mod = 1000000007;
long long Mod(long long n) {
long long t = 2;
long long res = 1;
while (n) {
if (n % 2 == 1)
res = ((res % mod) * t) % mod;
t = (t * t) % mod;
n = n / 2;
}
return res % mod;
}
int main() {
long long n;
cin >> n;
long long sum = ((n - 1) * Mod(n + 1)) % mod;
cout << sum << endl;
return 0;
}
/**
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* };
*/
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param root TreeNode类
* @return TreeNode类
*/
int process(int x, int base){
int cn = 0;
while(x%base == 0){
x /= base;
cn++;
}
return cn;
}
typedef pair<int, int>PII;
int t[100010], f[100010];
PII dfs(TreeNode* root){
if(!root)return {0, 0};
auto left = dfs(root->left);
auto right = dfs(root->right);
int val = root->val;
int five = process(val, 5);
int two = process(val, 2);
// if(left.first == -1 || right.first == -1){
// root->val = 0;
// return
// }
root->val = min(left.first+two+right.first, left.second+five+right.second);
return {left.first+two+right.first, left.second+five+right.second};
}
TreeNode* valueOfTree(TreeNode* root) {
// write code here
dfs(root);
return root;
}
};
相关推荐