1 /* 2 题意:问选出3个数成等比数列有多少种选法 3 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数。别人的代码很短,思维巧妙 4 */ 5 /************************************************ 6 * Author :Running_Time 7 * Created Time :2015-8-6 1:07:18 8 * File Name :C.cpp 9 ************************************************/ 10 11 #include <cstdio> 12 #include <algorithm> 13 #include <iostream> 14 #include <sstream> 15 #include <cstring> 16 #include <cmath> 17 #include <string> 18 #include <vector> 19 #include <queue> 20 #include <deque> 21 #include <stack> 22 #include <list> 23 #include <map> 24 #include <set> 25 #include <bitset> 26 #include <cstdlib> 27 #include <ctime> 28 using namespace std; 29 30 #define lson l, mid, rt << 1 31 #define rson mid + 1, r, rt << 1 | 1 32 typedef long long ll; 33 const int MAXN = 2e5 + 10; 34 const int INF = 0x3f3f3f3f; 35 const int MOD = 1e9 + 7; 36 map<ll, ll> c1, c2; 37 38 int main(void) { //Codeforces Round #Pi (Div. 2) C. Geometric Progression 39 ll ans = 0, x; ll n, k; 40 scanf ("%I64d%I64d", &n, &k); 41 for (int i=1; i<=n; ++i) { 42 scanf ("%I64d", &x); 43 if (x % (k * k) == 0) ans += c1[x/k]; //x可选作第三个数 44 if (x % k == 0) c1[x] += c2[x/k]; //x第三个数或第二个数 45 c2[x]++; 46 } 47 48 printf ("%I64d\n", ans); 49 50 return 0; 51 }
时间: 2024-12-17 01:22:18