中国剩余定理
来源:互联网 发布:网络电视直播手机版 编辑:程序博客网 时间:2024/06/07 23:48
POJ 1006 中国剩余定理模板
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int N=10;
int a[N],m[N]={11,23,28,33}; // x = ai (mod mi)
LL M;
void gcd(LL a,LL b, LL& d,LL& x,LL& y)
{
if(!b){d=a;x=1;y=0;}
else
{
gcd(b,a%b,d,y,x);
y-=x*(a/b);
}
}
LL china(int n,int a[],int m[])
{
LL d,y,x=0;
M=1;
for(int i=1;i<=n;i++) M*=m[i];
for(int i=1;i<=n;i++)
{
LL w = M / m[i];
gcd(m[i],w,d,d,y);
x = (x + y*w*a[i]) % M;
}
return (x+M)%M;
}
int main()
{
int day;int cas=0;
while(scanf("%d%d%d%d",&a[1],&a[2],&a[3],&day)!=EOF)
{
if(a[1]==-1) break;
LL ans = china(3,a,m);
ans-=day;
if(ans<=0) ans+=M;
printf("Case %d: the next triple peak occurs in ",++cas);
printf("%lld",ans);
printf(" days.\n");
}
return 0;
}
- 中国剩余定理模版【中国剩余定理】
- 中国剩余定理
- 中国剩余定理
- 中国剩余定理
- 中国剩余定理
- 中国剩余定理
- 中国剩余定理
- 中国剩余定理
- 中国剩余定理
- 数论-中国剩余定理
- 中国剩余定理
- 中国剩余定理
- 中国剩余定理
- 数论/中国剩余定理
- 关于《中国剩余定理》
- 中国剩余定理
- 模板[中国剩余定理]
- 中国剩余定理
- 最长公共子串【动态规划解法】
- 数据结构之希尔排序
- .net reflactor反编译以及依赖项处理——添加新表步骤
- 引用形参可以一个函数返回多个值
- Java中Interface的用法
- 中国剩余定理
- MySql按日期进行统计(前一天、本周、某一天)
- OC 打僵尸
- Ubuntu DNS server 设置
- scala学习笔记2(类,继承,抽象类)
- github版本库使用详细教程(命令行及图形界面版)
- Leetcode--Permutation Sequence
- XMPP协议----IQ
- viewstate