当前位置:网站首页>A. Div. 7
A. Div. 7
2022-07-04 01:48:00 【Felven】
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output
You are given an integer nn. You have to change the minimum number of digits in it in such a way that the resulting number does not have any leading zeroes and is divisible by 77.
If there are multiple ways to do it, print any of them. If the given number is already divisible by 77, leave it unchanged.
Input
The first line contains one integer tt (1≤t≤9901≤t≤990) — the number of test cases.
Then the test cases follow, each test case consists of one line containing one integer nn (10≤n≤99910≤n≤999).
Output
For each test case, print one integer without any leading zeroes — the result of your changes (i. e. the integer that is divisible by 77 and can be obtained by changing the minimum possible number of digits in nn).
If there are multiple ways to apply changes, print any resulting number. If the given number is already divisible by 77, just print it.
Example
input
Copy
3 42 23 377
output
Copy
42 28 777
Note
In the first test case of the example, 4242 is already divisible by 77, so there's no need to change it.
In the second test case of the example, there are multiple answers — 2828, 2121 or 6363.
In the third test case of the example, other possible answers are 357357, 371371 and 378378. Note that you cannot print 077077 or 7777.
Problem solving instructions : This problem is a math problem , According to the meaning of the topic, change a digit in the number as little as possible , Let the number be 7 to be divisible by , The easiest thing to think of is to change only the lowest position . First, count out the remainder , Compare the remainder with n The lowest point of , Remainder ratio n If the last digit of is small, then directly subtract the remainder , Otherwise, it will be added 7 Re reduction .
#include <stdio.h>
int main(void)
{
int t;
scanf("%d", &t);
while (t--)
{
int n, k;
scanf("%d", &n);
k = n % 7;
if (n % 10 - k<0)
{
n = n + 7 - k;
}
else
{
n = n - k;
}
printf("%d\n", n);
}
return 0;
}边栏推荐
- C import Xls data method summary I (upload files and create Workbooks)
- Mobile phone battery - current market situation and future development trend
- I don't know why it can't run in the project and how to change it
- Use classname to modify style properties
- Fundamentals of machine learning: feature selection with lasso
- Magical usage of edge browser (highly recommended by program ape and student party)
- When the watch system of Jerry's is abnormal, it is used to restore the system [chapter]
- Audio resource settings for U3D resource management
- Logical operator, displacement operator
- Typescript basic knowledge sorting
猜你喜欢

Meta metauniverse female safety problems occur frequently, how to solve the relevant problems in the metauniverse?

Example 073 square sum value judgment programming requires the input of a and B, if a ²+ b ² If the result of is greater than 100, a is output ²+ b ² Value, otherwise output the result of a + B.

Solution to the problem that jsp language cannot be recognized in idea

Long article review: entropy, free energy, symmetry and dynamics in the brain

How to use AHAS to ensure the stability of Web services?

Three layer switching ②

Huawei BFD and NQA

HackTheBox-baby breaking grad

What are the advantages and disadvantages of data center agents?

Some other configurations on Huawei's spanning tree
随机推荐
Small program graduation project based on wechat video broadcast small program graduation project opening report function reference
1189. Maximum number of "balloons"
Avoid playing with super high conversion rate in material minefields
be based on. NETCORE development blog project starblog - (14) realize theme switching function
Force buckle day32
Huawei BFD and NQA
Day05 table
Winter vacation daily question -- a single element in an ordered array
mysql使用視圖報錯,EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
Huawei cloud micro certification Huawei cloud computing service practice has been stable
Basic editing specifications and variables of shell script
Flex flexible layout, box in the middle of the page
Hunan University | robust Multi-Agent Reinforcement Learning in noisy environment
Notice on Soliciting Opinions on the draft of information security technology mobile Internet application (APP) life cycle security management guide
Fundamentals of machine learning: feature selection with lasso
In yolov5, denselayer is used to replace focus, and the FPN structure is changed to bi FPN
When the watch system of Jerry's is abnormal, it is used to restore the system [chapter]
Which insurance products can the elderly buy?
The contact data on Jerry's management device supports reading and updating operations [articles]
Openbionics robot project introduction | bciduino community finishing