2 条题解

  • 0
    @ 2023-12-7 19:30:07
    #include<bits/stdc++.h>
    using namespace std;
    int sum1[25],sum2[25];
    int main(){
    	int a,n,m,x;
    	cin>>a>>n>>m>>x;
    	sum1[2]=1,sum1[3]=2;
    	for(int i=4;i<n;i++){
    		sum1[i]=sum1[i-1]+sum1[i-2]-1;
    		sum2[i]=sum2[i-1]+sum2[i-2]+1;
    	}
    	int b=(m-a*sum1[n-1])/sum2[n-1];
    	cout<<a*sum1[x]+b*sum2[x];
    	return 0;
    }
    
    • 0
      @ 2023-8-7 17:01:06
      #include <iostream>
      #include <cstdio>
      #include <algorithm>
      #include <cstring>
      using namespace std;
      
      long long x,y,m,n,l;
      
      void gcd(long long a,long long b,long long& d,long long & x,long long& y)
      {
          if(!b)  {d=a;x=1;y=0;}
          else    {gcd(b,a%b,d,y,x);   y-=x*(a/b);}
      }
      
      int main()
      {
          cin>>x>>y>>m>>n>>l;
          long long a=((n-m)%l+l)%l;  long long b=l;    long long c=((x-y)%l+l)%l;
          long long d;
          gcd(a,b,d,x,y);
          if(c%d)
              cout<<"Impossible"<<endl;
          else
          {
              long long a1=x*(c/d);
              long long a2=abs(l/d);
              while(a1<0)
                  a1+=a2;
              while(a1-a2>=0)
                  a1-=a2;
              cout<<a1<<endl;
          }
          return 0;
      }
           
      
      
      
      • 1

      信息

      ID
      108
      时间
      1000ms
      内存
      256MiB
      难度
      9
      标签
      递交数
      9
      已通过
      4
      上传者