/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1090ms 26.781 MiB
#2 Accepted 1089ms 26.543 MiB
#3 Accepted 1094ms 26.766 MiB
#4 Accepted 1092ms 26.77 MiB
#5 Wrong Answer 1090ms 26.645 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define F                first
#define S                second
#define pb               push_back
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define P(ok)            cout << (ok ? "YES\n": "NO\n")
#define __Heart__              ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair< ll , ll>                   PII;
const int sz = 1e6 ;
vector<vector<ll>> dp(sz + 1);
ll lcmOfaAndb(ll a , ll b) {
  ll gc = __gcd(a , b) ;
  ll prod = a * b ;
  ll lc = prod / gc ;
  return lc ;
}
void PreCalc() {
    for(ll a = 2 ; a <= sz ; a++) {
        unordered_set<int> st;
        for(ll k = 1 ; k * a <= sz ; k++){
            ll b = lcmOfaAndb(k , a) - a ;
            if (b >= a && b <= sz && (a * b) % (a + b) == 0) st.insert(b) ;
        }
        for(auto it : st) dp[a].pb(it) ;
    }
}
void solve()
{
  ll n , Ans = 0; cin >> n ; ll a[n] ;
  map < int , int > freq ;
 for(auto  &x : a) cin >> x , freq[x]++ ;
 for(int i = 0 ; i < n ; i++){
    for(auto it : dp[a[i]]) {
        Ans += freq[it] ;
        if(it == a[i]) Ans-- ;
    }
    freq[a[i]]-- ;
 }
 cout << Ans << "\n" ;
}
int main()
{
     __Heart__
     PreCalc() ;
     int t ; t = 1; while(t--) solve() ;
}

Information

Submit By
Type
Submission
Problem
P1131 Count Special Pairs
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-08 23:54:38
Judged At
2024-11-11 02:22:36
Judged By
Score
80
Total Time
1094ms
Peak Memory
26.781 MiB