Skip to content

Instantly share code, notes, and snippets.

@modos
Created September 30, 2022 20:18
Show Gist options
  • Save modos/17935e15d1a9574cdc1520b9e467be6e to your computer and use it in GitHub Desktop.
Save modos/17935e15d1a9574cdc1520b9e467be6e to your computer and use it in GitHub Desktop.
الگو ساده
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner sr = new Scanner(System.in);
int n=sr.nextInt();
int sum=0,nine=9,dist=0,len;
for(len=1; ;len++)
{
sum+=nine * len;
dist+=nine;
if(sum>=n)
{
sum-=nine*len;
dist-=nine;
n-=sum;
break;
}
nine*=10;
}
int diff=(int)(Math.ceil((double)(n)/(double)(len)));
int d=n%len;
if(d==0)
{
d=len;
}
String str=Integer.toString(dist+diff);
System.out.println(str.charAt(d-1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment