题目学习——韩信点兵

1077 韩信点兵

时间限制:500MS  内存限制:65536K

Description

 相传汉高祖刘邦问大将军韩信统御兵士多少,韩信答说,每3人一列余1人、5人一列余2人、7人一列余4人、13人一列余6人、 17人一列余2人、19人一列余10人、23人一列余1人、29人一列余11人。

刘邦茫然而不知其数。你呢? 你是一位优秀的程序员,请你帮刘邦解决这一问题。 


输入格式

要求由键盘输入A,B,C,D,E,F,G,H,a,b,c,d,e,f,g,h十六个数,分别代表每A人一列余a、每B人一列余b、每C人一列余c、每D人一列余D、每E人一列余e、每F人一列余f、每G人一列余g、每H人一列余h,其中A,B,C,D,E,F,G,H为互不相等的质数


输出格式

输出总兵士数,要求输出满足条件的最小的一个,但要满足8种排法的每一种排法至少可排一列。(保证给的数据,有结果且计算的结果不会超过2的63次方)


输入样例

2 3 5 7 11 13 17 19
1 1 1 1 1 1 1 1


输出样例

9699691


暑假看了点数论,在网上看了些中国剩余定理,回头写这道数学题/呲牙


//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <iostream>
#include <bitset>
#include <algorithm>
using namespace std;

#define MP make_pair
#define PB push_back
#define mst(a,b) memset((a),(b),sizeof(a))
#define TEST cout<<"*************************"<<endl

#define rep(s,n,up) for(int i = (s); i < (n); i+=(up))
#define per(n,e,down) for(int i = (n); i >= (e); i-=(down))
#define rep1(s,n,up) for(int j = (s); j < (n); j+=(up))
#define per1(n,e,down) for(int j = (n); j >= (e); j-=(down))

typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<Pii> Vii;
const int inf = 0x3f3f3f3f;
const LL INF = (1uLL << 63) - 1;
const double Pi = acos(-1.0);
const int maxn = (1 << 16) + 7;
const uLL Hashmod = 29050993;
const double esp=1e-6;


//#define local


int main() {
#ifdef local
    freopen("input.txt", "r", stdin);
    //freopen("output.txt","w",stdout);
#endif
    //ios::sync_with_stdio(0);
    //cin.tie();
    LL divisor[8],remainder[8],tot_m=1,sum=0;
    rep(0,8,1)scanf("%lld",&divisor[i]);
    rep(0,8,1)scanf("%lld",&remainder[i]);
    LL min_sum=divisor[0]+remainder[0];
    rep(0,8,1){
        tot_m*=divisor[i];
        LL s=divisor[i]+remainder[i];
        if(s>min_sum)
            min_sum=s;
    }
    rep(0,8,1){
        LL m=1,temp_m=1;
        rep1(0,8,1){
            if(j!=i)
                m*=divisor[j];
        }
        temp_m=m;
        while(m%divisor[i]!=1)
            m+=temp_m;
        sum+=m*remainder[i];
    }
    sum%=tot_m;
    while(sum<min_sum)sum+=tot_m;
    printf("%lld\n",sum);
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值