赞
踩
C - Squared Error
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 300300 points
Given is a number sequence AA of length NN.
Find the sum of squared differences of every pair of elements: N∑i=2i−1∑j=1(Ai−Aj)2∑i=2N∑j=1i−1(Ai−Aj)2.
Input is given from Standard Input in the following format:
- NN
- A1A1 A2A2 A3A3 ⋯⋯ ANAN
Print the answer.
Copy
- 3
- 2 8 4
Copy
56
We have ∑Ni=2∑i−1j=1(Ai−Aj)2=(8−2)2+(4−2)2+(4−8)2=56∑i=2N∑j=1i−1(Ai−Aj)2=(8−2)2+(4−2)2+(4−8)2=56.
Copy
- 5
- -5 8 9 -4 -3
Copy
950
题解:

code:
- #include<bits/stdc++.h>
- #define INF 0x3f3f3f3f
- #define N 100003
- #define mod 100000
- #define pb push_back
- #define x first
- #define y second
- #define ull unsigned long long
- #define ll long long
- using namespace std;
- set<ll>s;
- int main()
- {
-
- ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- //freopen("in.txt", "r", stdin);
- //freopen("out.txt", "w", stdout);
- ll n;
- cin >> n;
- for(ll i = 2;i * i <= n;i++)
- {
- for(ll j = 2;;j++)
- {
- ll tmp = pow(i,j);
- if(tmp <= n)
- s.insert(tmp);
- else
- break;
- }
- }
- cout << n - s.size() << endl;
- return 0;
- }
-
-

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。