✅Short || C++ || Java || PYTHON || Explained Solution✔️ || Beginner Friendly ||🔥 🔥 BY MR CODER
Please UPVOTE if you LIKE!!\nWatch this video \uD83E\uDC83 for the better explanation of the code.\n\nhttps://www.youtube.com/watch?v=f0mAAQqvqR8\n\n\nAlso you 
**Please UPVOTE if you LIKE!!**\n**Watch this video \uD83E\uDC83 for the better explanation of the code.**\n\nhttps://www.youtube.com/watch?v=f0mAAQqvqR8\n\n\n**Also you can SUBSCRIBE  \uD83E\uDC81 \uD83E\uDC81 \uD83E\uDC81 this channel for the daily leetcode challange solution.**\n\nhttps://t.me/dsacoder  \u2B05\u2B05 **Telegram link** to discuss leetcode daily questions and other dsa problems\n\n\n**C++**\n```\nclass Solution {\npublic:\n#define ll long long\n#define MOD 1000000007\nint numFactoredBinaryTrees(vector& arr) {\nll ans =0;\nunordered_map<ll, ll> up;\nsort(arr.begin(), arr.end());\nfor(int i=0; i< arr.size(); i++){\nll currentans=1;\nfor(int j=0; j< i; j++)\n{\nif(arr[i]% arr[j]) continue;\nint ans1= arr[i]/ arr[j];\nint ans2= arr[j];\ncurrentans= (currentans+ up[ans1]*up[ans2]%MOD)%MOD;\n\n        }\n        up[arr[i]]= currentans;\n        ans = ans+ currentans;\n        \n    }\n    return ans% MOD;\n}\n};\n```\n**JAVA**\n```\nclass Solution {\n    public int numFactoredBinaryTrees(int[] arr) {\n        Arrays.sort(arr);\n        HashMap<Integer,Long>map=new HashMap<Integer,Long>();\n        long ans=1;\n        map.put(arr[0],ans);\n        for(int i=1;i<arr.length;i++)\n        {\n            long sum=1;\n            for(int j=0;j<i;j++)\n            {\n                if(arr[i]%arr[j]==0 && map.containsKey(arr[i]/arr[j]))\n                    sum=sum+(map.get(arr[i]/arr[j])*map.get(arr[j]));\n            }\n            map.put(arr[i],sum);\n            ans=ans+sum;\n        }\n        return (int)(ans%1000000007);\n    }\n}\n```\n**PYTHON**\n```\nclass Solution:\n    def numFactoredBinaryTrees(self, arr: List[int]) -> int:\n        \n        arr.sort()\n        MOD = 10**9 + 7\n        \n        # create a dictionary and initialize\n        dp = {}\n        for n in arr:\n            dp[n] = 1\n            \n        # loop through each number\n        for i, n in enumerate(arr):\n            for j in range(i):\n                if not(n % arr[j]) and n // arr[j] in dp:\n                    dp[n] += dp[arr[j]] * dp[n//arr[j]]\n                    dp[n] %= MOD\n        \n        return sum(dp.values()) % MOD\n```\n**Please do UPVOTE to motivate me to solve more daily challenges like this !!**
[]