51nod 1079 中国剩余定理

来源:互联网 发布:源码基地 编辑:程序博客网 时间:2024/05/21 06:42

题目传送门 : https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1079


一个正整数K,给出K mod 一些质数的结果,求满足条件的最小K,例如, K%2 == 1,K%3 == 2,k%5 == 3, K最小时是23。

此题是一道中国剩余定理的模版题,将被除数和余数分别存在p,m数组中,先令K = m[0],如果K%p[1] != m[1],则让k+=p[0],直到%p[1] == m[1],然后重复操作直到满足所有条件。(只试用于被除数两两互质)


代码如下:

<a target=_blank href="https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1079" style="font-size: 18px; font-weight: bold;">#include <iostream>#include <algorithm>#include <cstring>#include <stdio.h>#include <string>#include <cmath>#define ll long long#define mem(name,value) memset(name,value,sizeof(name))#define mod 1000000007#define PI 3.1415926#define E  2.718281828459using namespace std;const int maxn = 1005;double getlg(double x){    double cnt = 0;    while(x > 10){        x /= 10;        cnt++;    }    x += cnt;    return x;}int main() {    int t;    cin >> t;    for(int i=0;i<t;i++){        int n;        cin >> n;        ll res =  0.5 * log10(2.0 * PI * n) + n * log10(n * 1.0 / E) + 1;        cout << res << endl;    }    return 0;}</a><a target=_blank href="https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1079"></a>




0 0
原创粉丝点击