2019牛客网暑期多校第一场B题

登录—专业IT笔试面试备考平台_牛客网

https://ac.nowcoder.com/acm/contest/881/B











#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const int inf = 0x7f7f7f;
const int mod = 1e9 + 7;
typedef long long ll;

ll a[1010];



ll qpow(ll b, ll c) {
ll ans = 1;

while(c) {
if(c & 1)
ans = ans * b % mod;
b = b * b % mod;
c >>= 1;
}

return ans;
}



int main() {
//ios::sync_with_stdio(false);
#ifdef LOCAL
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
#endif

int n;
while(scanf("%d", &n) == 1) {
for(int i = 0; i < n; i++)
scanf("%lld", &a[i]);


ll ans = 0;
for(int i = 0; i < n; i++) {
ll mul = 1;


for(int j = 0; j < n; j++) {
if(j != i) {
mul *=  (a[j] * a[j] % mod - a[i] * a[i] % mod);
mul %= mod;
}
}


ans += (qpow(2 * a[i] % mod * mul % mod, mod - 2));
}

ans %= mod;
ans += mod; //确保ans最终为正
ans %= mod;
cout << ans << endl;
}
}


全部评论
这个图是手写的?好漂亮啊。
点赞 回复 分享
发布于 2019-07-19 16:59
字写的真好
点赞 回复 分享
发布于 2020-10-24 22:17
巨巨
点赞 回复 分享
发布于 2020-10-24 19:47

相关推荐

不愿透露姓名的神秘牛友
07-08 12:10
点赞 评论 收藏
分享
评论
7
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务