当前位置:网站首页>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;
}边栏推荐
- File contains vulnerability summary
- 0 basic learning C language - nixie tube dynamic scanning display
- C import Xls data method summary II (save the uploaded file to the DataTable instance object)
- Conditional test, if, case conditional test statements of shell script
- Three layer switching ①
- Gee: create a new feature and set corresponding attributes
- Logical operator, displacement operator
- Applet graduation project is based on wechat classroom laboratory reservation applet graduation project opening report function reference
- After listening to the system clear message notification, Jerry informed the device side to delete the message [article]
- Ka! Why does the seat belt suddenly fail to pull? After reading these pictures, I can't stop wearing them
猜你喜欢

Maximum entropy model

What are the advantages and disadvantages of data center agents?

String hash, find the string hash value after deleting any character, double hash

Will the memory of ParticleSystem be affected by maxparticles

Three layer switching ①

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

Three layer switching ②

Conditional statements of shell programming

Do you know the eight signs of a team becoming agile?

Applet graduation project is based on wechat classroom laboratory reservation applet graduation project opening report function reference
随机推荐
Huawei rip and BFD linkage
Day05 branch and loop (II)
C import Xls data method summary I (upload files and create Workbooks)
Some other configurations on Huawei's spanning tree
Hash table, string hash (special KMP)
ThinkPHP uses redis to update database tables
TP5 automatic registration hook mechanism hook extension, with a complete case
In yolov5, denselayer is used to replace focus, and the FPN structure is changed to bi FPN
Future source code view -juc series
Portapack application development tutorial (XVII) nRF24L01 launch C
Bacteriostatic circle scanning correction template
The force deduction method summarizes the single elements in the 540 ordered array
Stringutils and collectionutils
Luogu p1309 Swiss wheel
Yyds dry goods inventory it's not easy to say I love you | use the minimum web API to upload files
All ceramic crowns - current market situation and future development trend
Huawei cloud micro certification Huawei cloud computing service practice has been stable
mysql使用視圖報錯,EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
Introduction to Tianchi news recommendation: 4 Characteristic Engineering
Applet graduation project is based on wechat classroom laboratory reservation applet graduation project opening report function reference