Created
September 30, 2022 20:18
-
-
Save modos/17935e15d1a9574cdc1520b9e467be6e to your computer and use it in GitHub Desktop.
الگو ساده
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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