공지: 기존 사이트는 old.codingdojang.com에서 확인할 수 있으며, 2026년 8월 3일 종료됩니다.
이 페이지는 코딩도장 데이터의 읽기 전용 정적 보관본입니다.

수 암호화 프로그램

0~25만의 수 1개를 입력으로 받으면 그 수를 암호화하여 출력하는 프로그램을 작성하세요. 방법은 다음과 같습니다. 1. 입력받은 수의 제곱근에 1000을 곱한다. (예시: 2 => 1.414213... * 1000 => 1414.213...) 2. 1의 결과에서 소수점 이하를 버림한다. (예시: 1414.213... => 1414) 3. 2의 결과에서 입력받은 수를 뺀다.(예시: 1414 => 1414 - 2 => 1412) 이렇게 하면 2를 입력받았을 때 1412를 출력합니다. 다음 결과로 테스트하세요.

>>> password(2)
1412
>>> password(125000)
228553
>>> password(250000)
250000
>>> password(100000)
216227

난이도 Lv.1 예상합니다.

2021/01/30 10:17

이준우

재미있는 암호화 문제입니다. - 고태욱, 2021/03/02 22:12

56개의 풀이가 있습니다.

import math
def password(N):
    return math.trunc((N**0.5)*1000) - N

2021/01/30 22:01

BlakeLee

python 3.8.7입니다.

import math
def password(n):
    converted = int(math.sqrt(n) * 1000) - n
    return converted

실행 결과입니다.

>>> password(2)
1412
>>> password(125000)
228553

2021/01/31 15:41

이준우

def solution(N : int) -> int:
    return int((N ** 0.5) * 1000) - N

2021/02/02 20:09

김주영

import.java.util.*;

public class TEST {
 public static void main(String[] args) {
  Scanner in = new Scanner(System.in);
  int password = in.nextInt();
  int encrypt = math.sqrt(password) * 2 - password;
  System.out.println(encrypt);
 }
}

2021/02/05 17:07

땁땁

import math

n = int(input())

def password(n):
    x = int(math.sqrt(n) * 1000) - n
    return x

print(password(n))

2021/02/13 13:10

asdfa

def password(number):
    import math

    number = math.sqrt(number) * 1000
    number = int(number)
    number = number - 2

    print(number)

password(2)
password(3)

2021/02/17 23:34

Ael Lee

#include <stdio.h>
#include <math.h>

void main() {
    float i, result;

    printf("값을 입력해주세요 : ");
    scanf_s("%f", &i);

    result = (pow(i,0.5) * 1000) - i;

    printf("%d", (int)result);

    return 0;
}

C언어로 작성

2021/02/28 20:57

argo

x=int(input('0~25만의 정수 하나 입력'))

def password(e):
    org=e
    e=1000*e**0.5
    e=int(e)
    e-=2
    return e

print(password(x))

2021/03/13 10:29

최우진

import math

def password(a):
  print(int(math.sqrt(a)*1000) - a)

2021/03/14 22:51

김방이

def password(a):
  sqrt = (a ** 0.5) * 1000
  print(int(sqrt) - a)

2021/03/14 22:51

김방이

def password(n): x = int(math.sqrt(n) * 1000) - n return x

2021/03/17 21:36

OUT CHO

using System;

namespace 문제풀이_콘솔
{
    class Program
    {
        public static double password(double num)
        {
            double Sqrt = Math.Sqrt(num); //제곱근을 구함
            double result = Math.Truncate(Sqrt*1000) - num;
            return result;
        }

        static void Main(string[] args)
        {
            Console.Write("password : ");
            string input = Console.ReadLine();
            Console.WriteLine(password(Convert.ToDouble(input)));
        }
    }
}

2021/03/17 22:27

MinSeung Kang

def password(num):
    return int(num**0.5 * 1000)-num

print(password(2))
print(password(125000))
print(password(250000))
print(password(100000))

2021/03/25 12:59

잘해보자

import math

def password(n):
    step1 = n ** (1/2) * 1000
    step2 = math.trunc(step1)
    return step2 - n

2021/04/05 14:27

돈 벌면 뭐하노

Julia 입니다.

const password(n) = Int(floor((1000 * √n) - n))

let s = parse(Int, readline())
    s |> password |> println
end

2021/04/12 10:34

룰루랄라

print(int((number ** 0.5) * 1000 - 2))

2021/04/12 22:38

whalerice

import java.util.Random; import java.util.Scanner;

//암호화 하기 public class PassCode { public static void main(String[] args) { double a=0;//임의의 수 0~~~25만 double b=0;//제곱근 int c=0;//정수로 바꾸기

Scanner scan= new Scanner(System.in);
Random ran= new Random();
    a= ran.nextInt(250000);
    System.out.println("=====>password("+a+")");
    b=(int)Math.floor(Math.sqrt(a)*1000);


    System.out.println(b);

}//main }//class

2021/04/16 12:30

이동훈

import math

def password(n):
    code_num = math.floor(math.sqrt(n)*1000) - n
    return code_num

n = int(input())
print(password(n))

2021/04/29 16:42

bravesong

Python

math 패키지를 활용, def로 정의한 후 숫자를 input 받아 처리하는 로직

import math


def password(i):
    a = math.trunc(int(i)**(1/2)*1000)-int(i)
    print(a)


x = input("숫자를 입력하세요. : ")
password(x)

2021/05/12 11:50

K

import math
password = int(input())
if password in range(250000+1):
    print(math.floor(1000*math.sqrt(password))-password)
else: print("password is not in range")

2021/05/23 15:46

ss2663

import math

x = int(input('암호화 :'))

if 0<x<250000 :
    i = int(math.sqrt(x)*1000)-x
    print(i)
else : print('25만 이하로 입력하세요')

2021/05/24 11:01

약사의혼자말

import math
n = int(input("숫자를 입력 바랍니다 : "))

value = int(math.sqrt(n) *1000) - n
print("해당 값 : " ,value)

2021/06/27 13:03

semipooh

#codingdojing_encryption

from math import *

def password(n):

    print(floor(sqrt(n)*1000)-n)

password(2)
password(125000)
password(250000)
password(100000)

2021/07/15 18:21

Jaeman Lee

파이썬 3.8.10으로 작성했습니다.

import math
password = input().strip()
print(eval(str(math.sqrt(int(password))*1000).split('.')[0] + '-' + password))

2021/07/28 17:39

baek choi

def password(N):
    print(int(N**0.5 * 1000) - N)

2021/08/10 05:17

[w]*눈꽃*

C#

using System;

namespace 수암호화프로그램
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine(GetPassword(100000));
        }

        static int GetPassword(int number) => (int)(Math.Sqrt(number) * 1_000) - number;
    }
}

2021/08/19 14:05

mohenjo

def password(n):
    x= int(n**0.5 * 1000) - n
    return x
test=[2,125000,250000,100000]
for i in test:
    print(password(i))

2021/09/20 15:40

ninanino

a=float(input('암호화할수를 입력하시오')) b=a*(1/2) c=b1000 d=int(c) e=d-a print(e)

2021/09/24 10:47

ᄋᄋᄋ

import math
num=int(input())
a= int((math.sqrt(num))*1000 - num)
print(a)

2021/10/20 14:09

ottato

static void password(int x) {
        System.out.println((int) (Math.sqrt(x) * 1000) - x);
    }

    public static void main(String[] args) {
        password(2);
        password(125000);
        password(250000);
        password(100000);
    }

2021/10/23 22:17

박대현

코딩 배운지 1주일도 안 된 코린이입니다. 꾸벅.

a = int(input("0 - 250000의 정수를 입력하세요."))
b = int((a**(1/2))*1000) - a
print(">>>>password(%d)" % a, "\n%d" % b)

2021/11/11 10:45

최승철

def password(x):
    return int(x**0.5*1000)-x

2021/11/22 18:21

황성민

security = int(input(">>password :"))
security =  int((security**(1/2))*1000) - security
print(security)

2021/12/16 10:49

정설경

import math

a = int(input())

def password (a) :
    a1 = math.sqrt(a)*1000
    a2 = math.trunc(a1)
    a3 = a2 - a
    return print(a3)

password(a)

2021/12/19 00:40

양캠부부

n = int(input()) print(int(n ** .5 * 1000) - n)

2021/12/30 23:39

Noname

def password(n): return int((n*(0.5))1000) - n

password(2)

2022/01/14 09:16

seolgyung jeong

def password(a):
    return round(math.sqrt(a)*1000)-a

list(map(password,[2,125000, 250000, 216227]))

2022/01/26 16:27

로만가

import java.util.Scanner;
import java.util.*;

public class Password {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int password = sc.nextInt();
        double encrypt = Math.sqrt(password) * 1000; //1.입력받은수 제곱근값에 1000을 곱한다
        encrypt = Math.round(encrypt);          //2.소수점을 버린다
        encrypt -= password;            //3.2의 결과에서 입력받은수를 뺀다
        System.out.println(encrypt);
    }

}

2022/02/09 10:34

이인범

package org.javaturotials.ex;
import java.util.*;

public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double num = sc.nextDouble();
        num = (Math.sqrt(num)*1000)-num;
        int a =(int)num;
        System.out.println(a);
        }
    }

2022/02/17 21:25

Kkubuck

package section01;

import java.util.Scanner;

public class MathCalc {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        System.out.print("숫자를 입력해주세요 : ");
        int num = sc.nextInt();
        int num2 = (int)(Math.sqrt(num) * 1000);
        int result = num2 - num;
        System.out.println(result);

    }

}

2022/02/26 14:14

sw

import math

def password(x):
  return math.floor((math.sqrt(x) * 1000)) - x

2022/03/24 22:55

Charles

import math as m
n=int(input("#"))
print(m.floor((n**(0.5))*1000)-n)

2022/05/10 17:30

yunjae

def pw(n):
    return int(n**0.5*1000) - n

ui = int(input("0~25만 사이 자연수 입력>> "))
print(pw(ui))

2022/07/14 23:41

Estelle L

import java.util.Scanner;

public class Password {

    public static void main(String[] args) {
        System.out.println("입력하세요.");
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();

        double num = Double.parseDouble(str);
        double sqrtnum = Math.sqrt(num);

        System.out.println((int)(sqrtnum*1000)-(int)num);
    }
}

2022/08/01 23:27

허유나

import math as m
a = int(input("숫자 입력 : "))
print((round(m.sqrt(a)*1000)) - 2)

2022/08/30 21:42

코딩재미

import math

def password (num):
    result=str(math.sqrt(num)*1000)
    result=int(result[:result.index('.')])-num        
    return result

num=int(input('num?'))
print (password(num))

2022/09/09 01:46

Buckshot

버림을 하는 명령어가 기억이 안나서 저렇게 작성을 해봤습니다. 덕분에 좀 길어졌네요.. - Buckshot, 2022/09/09 01:47

Python. 적절한 변수명 정하는 게 은근히 신경 쓰이는군요.

import math
origin=int(input('임의의 수를 입력하시오. : '))
processing_number=math.sqrt(origin)*1000//1
encoded_number=processing_number-origin
print('암호화된 수는 {0:0.0f}입니다.'.format(encoded_number))

2022/10/31 13:58

Frye 'de Bacon

python

import math

number = float(input("숫자를 입력하시오: "))

num = math.sqrt(number) * 1000
ciper = int(math.trunc(num) - number)

print(f"암호: {ciper}")

java

import java.util.Scanner;

public class password 
{
    public static void main(String[] args) 
    {
        int num = 0; //입력받는 정수값
        double number = 0.0; //암호화 과정 중간값
        int new_password = 0; //새로운 암호

        Scanner scanner = new Scanner(System.in);

        System.out.printf("0~250000의 숫자를 입력해주세요");
        num = scanner.nextInt();

        number = Math.sqrt(num) * 1000;
        number = Math.floor(number); 
        new_password = (int)number - num;

        System.out.printf("%d", new_password);
    }
}

2022/11/13 22:53

김성범

import math
n = int(input())
print(math.floor(n ** 0.5 * 1000) - n)

Python

2022/12/22 13:49

마라떡볶이

import math

numb=int(input())
outNum=int((math.sqrt(numb))*1000)-numb

print(outNum)

2023/03/13 13:24

Sol Song

num = int(input("Enter Number:"))
code_num = int(num**(1/2)*1000)-num
print(code_num)

2023/07/06 17:38

siu yoon

using System;

namespace solution
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("암호화 할 0~25만 사이의 수 1개를 입력하세요: ");
            int N = int.Parse(Console.ReadLine());

            Console.WriteLine((int)(Math.Sqrt(N) * 1000) - N);
        }
    }
}

2023/07/12 13:36

insperChoi

import math

a = input ("숫자를 입력하세요: ")
n = int(a)

def password(n):
    return math.trunc((n**0.5)*1000) - n

print (password(n))

2023/07/26 18:49

RMichael

num = int(input("숫자 입력: "))
print(int(((num**0.5) * 1000)-num))

2025/02/25 15:22

Dasol Lee

import math

while True:
    pwd = int(input("0~25만의 수 중 하나 입력: "))
    if pwd > 2.5e+05 :
        print("숫자가 너무 큽니다.")
        continue
    a = math.sqrt(pwd)*1000
    b = math.trunc(a) #소수점 아래 자리 버림
    c = b-pwd
    break
print(f"password: %d"%c)

2025/08/21 21:57

허거덩

코드입니다.

import math
n=int(input())
def password(arr):
  return math.trunc(math.sqrt(arr)*1000)-arr
print(password(n))

2025/09/14 20:12

임지호

목록으로