Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <fstream>
- using namespace std;
- int main()
- {
- // ifstream cin("1029ET_8.IN");
- // ofstream cout("in.txt");
- ios_base::sync_with_stdio(false);
- // x % k = y
- int n,k;
- cin>>n>>k;
- int x[n];
- int cnt=0;
- int maks =0 ;
- for(int i = 0;i<n;i++){
- cin>>x[i];
- maks = max(maks, x[i]);
- }
- vector<int> counter(1e6 + 10, 0);
- for(int i = 0;i<n;i++){
- counter[x[i]]++;
- }
- for(int i = 0; i < n; i++) {
- int res = 0;
- if(x[i] == k) {
- for(int j = 0; j < n; j++) {
- if(i != j and x[j] >= x[i]) {
- if(x[i] % x[j] == k){
- res++;
- }
- }
- }
- }
- else {
- int num = x[i] - k;
- if(num <= 0) {
- for(int j = 0; j < n; j++) {
- if(i != j and x[i] == x[j]) {
- res++;
- }
- }
- }
- else {
- // cout << x[i] << ": ";
- for(int j = 1; j <= sqrt(num) + 1; j++) {
- if(num % j == 0) {
- // cout << j << endl;
- if(x[i] % j == k) {
- if(j != x[i]) {
- res += counter[j];
- }
- else {
- res += counter[j] - 1;
- }
- }
- if(j != num / j) {
- int del = num / j;
- // cout << del << " " ;
- if(x[i] % del == k) {
- if(del != x[i]) {
- res += counter[del];
- }
- else {
- res += counter[del] - 1;
- }
- }
- }
- }
- }
- }
- }
- cout << res << " ";
- }
- return 0;
- if(n<=2000){
- for(int i = 0;i<n;i++){
- for(int j = 0;j<n;j++){
- if(x[i]%x[j]==k && i!=j){
- cnt++;
- }
- }
- cout<<cnt<<" ";
- cnt=0;
- }
- return 0;
- }
- if(k == 0) {
- for(int i = 0; i < n; i++) {
- int res = 0;
- int sq = sqrt(x[i]);
- for(int j = 1; j <= sq; j++) {
- if(x[i] % j == 0) {
- res += counter[j];
- if(j != x[i] / j) {
- if(x[i] / j == x[i]) {
- res += counter[x[i] / j] - 1;
- }
- else {
- res += counter[x[i] / j];
- }
- }
- }
- }
- cout << res << " ";
- }
- }
- else {
- for(int i = 0; i < n; i++) {
- int res = 0;
- for(int j = 1; j <= maks; j++) {
- if(x[i] % j == k) {
- if(j == x[i]) {
- res += counter[j] - 1;
- }
- else {
- res += counter[j];
- }
- }
- }
- cout << res << " ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement