# 精度问题

__int128 快（龟）速（速）乘（乘）是个不错的主意。

1 int mul(int x,int k,int mod) {
2     ll ans=0;
3     while(k) {
4         if(k&1)(ans+=x)%=mod;
5         k>>=1;
6         (x<<=1)%=mod;
7     }
8     return ans;
9 }

# 题目

 1 #include<bits/stdc++.h>
2 using namespace std;
3 #define INF 0x7fffffff
4 #define ME 0x7f
5 #define FO(s) freopen(s".in","r",stdin);freopen(s".out","w",stdout)
6 #define fui(i,a,b,c) for(int i=(a);i<=(b);i+=(c))
7 #define fdi(i,a,b,c) for(int i=(a);i>=(b);i-=(c))
8 #define fel(i,a) for(register int i=hd[a];i;i=dg[i].nxt)
9 #define ll long long
10 #define int long long
11 #define MEM(a,b) memset(a,b,sizeof(a))
12 #define maxn 100010
13 ll n;
14 ll a[maxn],b[maxn],a0,b0;
15 template<class T>
17     n=0;int t=1;double x=10;char ch;
18     for(ch=getchar();!isdigit(ch)&&ch!='-';ch=getchar());(ch=='-')?t=-1:n=ch-'0';
19     for(ch=getchar();isdigit(ch);ch=getchar()) n=n*10+ch-'0';
20     if(ch=='.') for(ch=getchar();isdigit(ch);ch=getchar()) n+=(ch-'0')/x,x*=10;
21     return (n*=t);
22 }
23 template<class T>
24 T write(T n){
25     if(n<0) putchar('-'),n=-n;
26     if(n>=10) write(n/10);putchar(n%10+'0');return n;
27 }
28 template<class T>
29 T writeln(T n){write(n);putchar('\n');return n;}
30 int exgcd(int a,int b,int &x,int &y){
31     if(!b)return a+((x=1)*(y=0));
32     int xx,yx,z;z=exgcd(b,a%b,xx,yx);
33     x=yx,y=xx-a/b*yx;return z;
34 }
35 int gcd(int a,int b){if(!b)return a;return gcd(b,a%b);}
36 int mul(int x,int k,int mod){
37     ll ans=0;
38     while(k){
39         if(k&1)(ans+=x)%=mod;
40         k>>=1;
41         (x<<=1)%=mod;
42     }
43     return ans;
44 }
45 signed main(){
48     a0=a[1],b0=b[1];
49     fui(i,2,n,1){
50         int c=gcd(a0,a[i]),d1=a0/c,d2=a[i]/c,p,x,y;
51         int a1=a0,a2=a[i],b1=b0,b2=b[i];
52         if(((b2-b1)/c*c)^(b2-b1))return 0*writeln(-1);
53         exgcd(d1,d2,p,y);((p%=d2)+=d2)%=d2;
54         x=mul(p,(((b2-b1)/c)%d2+d2)%d2,d2)*a1+b1;
55         y=a1*d2;b0=x,a0=y;((b0%=a0)+=a0)%=a0;
56     }
57     int x,y;exgcd(1,a0,x,y);
58     ((x%=a0)+=a0)%=a0;
59     x=mul(x,b0,a0);
60     writeln(x);
61     return 0;
62 }
AC代码

好像还有NOI2018屠龙勇士？23333先等我去A掉它

posted @ 2018-10-17 22:20  A星际穿越  阅读(165)  评论(0编辑  收藏  举报