题解 | 抽卡-java

抽卡

https://www.nowcoder.com/practice/cddfb87d552c468d9176e95efffa7b3c

import java.util.Scanner;

public class Main {
    static long mod=(long)1e9+7;
    static long qpow(long a,long b){
        long ans=1;
        a%=mod;
        while (b>0) {
            if((b&1)==1) ans=(ans*a)%mod;
            a=(a*a)%mod;
            b>>=1;
        }
        return ans;
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        long[]a=new long[n+1];
        long[]b=new long[n+1];
        for (int i = 1; i <=n; i++) {
            a[i]=sc.nextLong();
        }
        for (int i = 1; i <=n; i++) {
            b[i]=sc.nextLong();
        }
        long ans=1;
        for (int i = 1; i <=n; i++) {
            long tem=(a[i]-b[i])%mod;
            long inv=qpow(a[i], mod-2);
            long res=(tem*inv)%mod;
            ans=(ans*res)%mod;
        }
        System.out.println((mod+1-ans)%mod);
        sc.close();
    }
}

#java#
全部评论

相关推荐

xtu大迫杰:偶遇校友,祝校友offer打牌
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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