リンク/カットツリーCodeForces-614A暴力+バーストロングロングハンドリング

トピック:

間隔[l、r]を指定し、k ^ xを小から大に出力し、y = k ^ xを設定して、yが間隔[l、r]にあることを確認

 

解決策:

kが最小の2であっても、long longの制限に到達するために何度も列挙する必要がないため、暴力は議論されておらず、TLEにはなりません。

次に、長いロングバーストを処理します。たとえば、rは非常に大きいです。k^ x = <rだがk ^(x + 1)の場合、ロングロングバーストには注意してください。

 

コード:

1 #include <stdio.h>
 2 #include < string .h>
 3 #include <iostream>
 4 #include <algorithm>
 5 #include <queue>
 6 #include <map>
 7 #include <vector>
 8 #include < math.h>
 9  #define mem(a、x)memset(a、x、sizeof(a))
 10  名前空間std を使用 ;
11 typedef long long ll;
12 CONST INT MAXN = 1200000 + 10 13 const int mod = 26     ;
14  const  int INF = 0x3f3f3f3f ;
15  const  int Times = 10 ;
16  const  int N = 5500 ;
17  int main()
 18  {
 19      ll l、r、k;
20      cin >> l >> r >> k;
21      int isp = 0 ;
22      ll ans = 1 ;
23      while1 24      {
 25          if(ans> = l && ans <= r)
26          {
 27              cout << ans << "  " ;
 28              isp = 1 ;
 29          }
 30          if(r / ans <k)    // 判定r <ans * k、
31          {
 32              break ; // ans * kは範囲外、すべて除算
33          }
 34          ans * = k;
 35      }
 36      if(isp == 0 37      {
 38          cout << " -1 " << endl;
39      }
 40      else 
41      {
 42          cout << endl;
43      }
 44は     0を返し ます45 }

 

おすすめ

転載: www.cnblogs.com/kongbursi-2292702937/p/12678517.html