2 条题解

  • 2
    @ 2025-9-18 20:40:39

    与502. 序列的第 k 个数一模一样

    AC CODE

    #include<queue>
    #include<math.h>
    #include<stdio.h>
    #include<iostream>
    #include<vector>
    #include<iomanip>
    #include<string.h>
    #include<algorithm>
    #include<cmath>
    #include<cstdio>
    #include<utility>
    #include<cstring>
    #include<stack>
    #include<fstream>
    #include<string>
    using namespace std;
    #define LL long long
    const int N = 1e5 + 10;
    const int INF = 0x3f3f3f3f;
    const long long M = 200907;
    long long q( long long a , long long b )
    {
    	long long ret = 1;
    	while ( b != 0 )
    	{
    		if ( b % 2 == 1 ) 
    		{
    			ret = ( ret * a % M ) % M;
    		}
    		a = a * a % M;
    		b /= 2;
    	}
    	return ret % M;
    }
    long long a , b , c;
    long long k;
    long long t;
    int main()
    {
    	cin >> t;
    	while ( t-- )
    	{
    		cin >> a >> b >> c >> k;
    		if ( b - a == c - b ) 
    		{
    			long long d = ( b - a ) % M;
    			cout << ( ( k - 1 ) % M * d + a % M ) % M << endl;
    		}
    		else 
    		{
    			long long d = b / a % M;
    			cout << ( q( d , k -1 ) * a % M ) % M << endl;
    		}
    	}
    	return 0;
    }
    
    • 0
      @ 2026-6-12 17:39:38
      #include<bits/stdc++.h>
      using namespace std;
      long long fp(long long a, long long b, long long m){
      	long long res=1;
      	a=a%m;
      	while(b>0){
      		if(b%2==1){
      			res=(res*a)%m;
      		}
      		a=(a*a)%m;
      		b/=2;
      	}
      	return res;
      }
      long long gt(long long a,long long b,long long c,long long k){
      	if(b-a==c-b){
      		long long d=b-a;
      		return (a+(k-1)*d)%200907;
      	}else{
      		long long q=b/a;
      		return (a*fp(q,k-1,200907))%200907;
      	}
      }
      int main(){
      	int t;
      	cin >> t;
      	while(t--){
      		long long a,b,c,k;
      		cin>>a>>b>>c>>k;
      		long long rst=gt(a,b,c,k);
      		cout<<rst<<endl;
      	}
      	return 0;
      }
      
      
      • 1

      信息

      ID
      3038
      时间
      1000ms
      内存
      256MiB
      难度
      10
      标签
      递交数
      8
      已通过
      5
      上传者