Dãy số: 1,2,3,4,5,6,7,8,9,11,22,33,44,55 ....[Cơ bản]
Xem dạng PDF
Gửi bài giải
Điểm:
20,00 (OI)
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
256M
Input:
stdin
Output:
stdout
Dạng bài
Ngôn ngữ cho phép
PyPy, Python, Scratch
Cho dãy số: 1,2,3,4,5,6,7,8,9,11,22,33,44,55,66,77,88,99,111,222,333,444,555 ....
Viết chương trình tìm số hạng thứ N của dãy số trên.
Ví dụ:
Input:
9
Ouput:
9
Ví dụ 2:
Input:
12
Ouput:
33
Bình luận
n = int(input())
d = (n - 1) % 9 + 1
l = (n - 1) // 9 + 1
print(int(str(d) * l))
def findnthterm(n): # Xác định số chữ số m của số thứ n m = (n - 1) // 9 + 1 # Xác định chữ số lặp lại d d = n - 9 * (m - 1) # Tính số hạng thứ n: d * (10^m - 1) / 9 term = d * (10**m - 1) // 9 return term
Ví dụ: Tìm số hạng thứ 23
n = int(input()) print(findnthterm(n)) # Kết quả: 555
strong text N = int(input()) K = N % 9 if K == 0: K = 9 D = N // 9 + (N % 9 != 0) print(str(K) * D)
// Online C++ Compiler - Build, Compile and Run your C++ programs online in your favorite browser
include<iostream>
using namespace std;
int main() { cout<<"Welcome to Online IDE!! Happy Coding :)"; return 0; }
N = int(input())
sequence = [] length = 1
while len(sequence) < N: for d in range(1, 10): number = int(str(d) * length) sequence.append(number) if len(sequence) == N: print(number) break length += 1 code dây nhé
import math N = int(input()) soso = math.ceil(N / 9) chuso = N % 9 if chuso == 0: chuso = 9 print(str(chuso) * soso)
Online Python - IDE, Editor, Compiler, Interpreter
def sum(a, b): return (a + b)
a = int(input('Enter 1st number: ')) b = int(input('Enter 2nd number: '))
print(f'Sum of {a} and {b} is {sum(a, b)}')
Chép thoải mái
include <iostream>
include <cmath>
int main() { int a; std::cin>>a; int b=a/9; int c=a%9; if (c==0) { c=9; } int d=c; int i=0; for (int x=0;x<b+1;x++) { i+=c; c=10; } if (d==9) { i-=d(pow(10,b)); } std::cout<<i; return 0; }
?name=<a href="javascript:window.location='https://www.youtube.com/watch?v=dQw4w9WgXcQ'">Nhận quà</a>
Vui lòng tôn trọng tôi bằng cách không copy-paste. Chỉ dùng code này nếu bạn bí ý tưởng.
Bạn chỉ gợi ý hoặc spoiler lại và ghi tên mình(hoặc cái gì đó khác để khi ai copy là dễ phát hiện, VD: code