Contacts can be duplicated , but they don't multiply ( repeat ) forty times or more .
If you have signed in with same Apple ID and password on the same network in Mac and iPhone or other apple devices the contacts on each device will get synced , if the same contacts are in devices they will be seen as duplicates ( as if you had already created contacts in Mac and the same are in iPhone ) .
To avoid it , disconnect the desired device by just signing out from Apple ID account , then delete the duplicate contacts in each device .
Second method .
When Apple ID is signed in Mac and application contact is turned on Set up iCloud features on Mac – Apple Support
If you select duplicate contacts from Mac and delete them , automatically they will be deleted from iCloud.com
The duplicates contacts ( they will be under iCloud section > in All iCloud ) are shown in Mac address book as well as in iCloud.com if these duplicate contacts are selected from Mac address book use command and A keys and click on command and delete key they will be deleted condition they must be in series and not randomly placed , as important contacts will also be deleted .
If they are randomly placed select important contacts that are not to be deleted in on my Mac section , just select use command and A keys , copy use command and C keys and paste use command and V keys .
The duplicate contacts can also be in various groups in iCloud.com Create a group of contacts on iCloud.com - Apple Support created and they will be shown in All contacts of Mac address book ( see the first option ) .
You need to find out duplicate contacts of address book search from various groups , All contacts , All iCloud and another way is create a group name as say duplicate contacts1 find out all duplicates and club in this folder and finally delete this folder it will be removed from address book / iCloud.com
The Iphone / iPad are synced , the duplicate contacts will be deleted .