zoukankan      html  css  js  c++  java
  • 51nod 1079 中国剩余定理(模板题)

    1079 中国剩余定理

    基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题
    收藏
    关注
    一个正整数K,给出K Mod 一些质数的结果,求符合条件的最小的K。例如,K % 2 = 1, K % 3 = 2, K % 5 = 3。符合条件的最小的K = 23。
    Input
    第1行:1个数N表示后面输入的质数及模的数量。(2 <= N <= 10)
    第2 - N + 1行,每行2个数P和M,中间用空格分隔,P是质数,M是K % P的结果。(2 <= P <= 100, 0 <= K < P)
    Output
    输出符合条件的最小的K。数据中所有K均小于10^9。
    Input示例
    3
    2 1
    3 2
    5 3
    Output示例
    23
    #include <iostream>
    #include <algorithm>
    
    using namespace std ; 
    
    #define LL long long
    #define maxn 10000
    LL ans ; 
    LL P[maxn] , M[maxn] ; 
    
    int main(){
    
        int n ; 
        while(cin >> n ){
            for(int i=0 ; i<n ; i++){
                cin >> P[i] >> M[i] ; 
            }
            LL gg = 1 ; 
            ans = M[0] ; 
            for(int i=0 ; i<n-1 ; i++){
                gg = gg * P[i] ; 
                while(ans%P[i+1]!=M[i+1]){
                    ans += gg ; 
                }            
            }
    
            cout << ans << endl ; 
        }
    
        return 0 ; 
    
    }
  • 相关阅读:
    机器学习项目流程(二)探索并可视化数据
    机器学习项目流程(一)初探数据集
    数据类型.md
    keepalived.md
    LVS.md
    tomcat多实例.md
    LANMP常用配置.md
    php-fpm配置参数.md
    Nginx学习.md
    Redis.md
  • 原文地址:https://www.cnblogs.com/yi-ye-zhi-qiu/p/9311371.html
Copyright © 2011-2022 走看看