Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Number of unique digits numbers 1-5324
- = Number of unique digits numbers 1-9
- + Number of unique digits numbers 10-99
- + Number of unique digits numbers 100-999
- + Number of unique digits numbers 1000-5324
- f(n) = Number of unique digits numbers with length n.
- f(1) = 9 (1-9)
- f(2) = 9*9 (1-9 * 0-9 (excluding first digit))
- f(3) = 9*9*8 (1-9 * 0-9 (excluding first digit) * 0-9 (excluding first 2 digits))
- f(4) = 9*9*8*7
- Number of unique digits numbers 1000-5324
- = Number of unique digits numbers 1000-4999
- + Number of unique digits numbers 5000-5299
- + Number of unique digits numbers 5300-5319
- + Number of unique digits numbers 5320-5324
- N = 5324
- If N[0] = 1, there are 9*8*7 possibilities for the other digits
- If N[0] = 2, there are 9*8*7 possibilities for the other digits
- If N[0] = 3, there are 9*8*7 possibilities for the other digits
- If N[0] = 4, there are 9*8*7 possibilities for the other digits
- If N[0] = 5
- If N[1] = 0, there are 8*7 possibilities for the other digits
- If N[1] = 1, there are 8*7 possibilities for the other digits
- If N[1] = 2, there are 8*7 possibilities for the other digits
- If N[1] = 3
- If N[2] = 0, there are 7 possibilities for the other digits
- If N[2] = 1, there are 7 possibilities for the other digits
- If N[2] = 2
- If N[3] = 0, there is 1 possibility (no other digits)
- If N[3] = 1, there is 1 possibility (no other digits)
- If N[3] = 2, there is 1 possibility (no other digits)
- If N[3] = 3, there is 1 possibility (no other digits)
- uniques += (N[0]-1)*9!/(9-N.length+1)!
- for (int i = 1:N.length)
- uniques += N[i]*(9-i)!/(9-N.length+1)!
- // don't forget N
- if (hasUniqueDigits(N))
- uniques += 1
- binary used[10]
- uniques += (N[0]-1)*9!/(9-N.length+1)!
- used[N[0]] = 1
- for (int i = 1:N.length)
- uniques += (N[i]-sum(used 0 to N[i]))*(9-i)!/(9-N.length+1)!
- if (used[N[i]] == 1)
- break
- used[N[i]] = 1
- // still need to remember N
- if (hasUniqueDigits(N))
- uniques += 1
- Prelude> :m +Data.List
- Data.List> length [a | a <- [1..5324], length (show a) == length (nub $ show a)]
- 2939
- import java.io.*;
- import java.util.*;
- import java.text.*;
- import java.math.*;
- import java.util.regex.*;
- public class Solution {
- public static void main(String[] args) {
- int rem;
- Scanner in=new Scanner(System.in);
- int num=in.nextInt();
- int length = (int)(Math.log10(num)+1);//This one is to find the length of the number i.e number of digits of a number
- // System.out.println(length);
- int arr[]=new int[length]; //Array to store the individual numbers of a digit for example 123 then we will store 1,2,3 in the array
- int count=0;
- int i=0;
- while(num>0) //Logic to store the digits in array
- { rem=num%10;
- arr[i++]=rem;
- num=num/10;
- }
- for( i=0;i<length;i++) //Logic to find the duplicate numbers
- {
- for(int j=i+1;j<length;j++)
- {
- if(arr[i]==arr[j])
- {
- count++;
- }
- }
- }
- //Finally total number of digits minus duplicates gives the output
- System.out.println(length-count);
- }
- }
Add Comment
Please, Sign In to add comment