FOJ Playing with Calculator (模运算)
来源:互联网 发布:判断矩阵计算公式 编辑:程序博客网 时间:2024/05/17 18:49
Problem Description
Pete is playing a game. He types on a calculator a natural number K and then presses the '+' key. The display still shows K. Pete wants to have on the display a number that is formed using only one figure. In order to get that he presses, if it is necessary, the '=' key several times (maybe 0). The result after the first pressing is K+K. After each pressing the number K is added to the sum. Find out whether Pete will achieve his goal or not, and what number, consisting all of identical figures, he will get first. Consider the capacity of the calculator to be unlimited.
K < 1000
Input
The input file contains the number K.
Process to the end of file.
Output
Sample Input
Sample Output
大致题意,给你一个数k,n*k==result, result由相同数字组成,输出数字和这个数字的个数。转化成就是result能被k整除,由于result是有相同数字组成的,所以求模可以递推进行计算。
AC代码:
# include <stdio.h> int main(){int i, j, k, a, b, flage, n;int f[10010];while(scanf("%d", &n)!=EOF){flage=0;for(i=1; i<=9; i++){f[0]=0;for(j=1; j<=n; j++){f[j]=(f[j-1]*10+i)%n;if(f[j]==0){printf("%d %d\n", i, j);flage=1;break;}}if(flage){break;}}if(!flage)printf("-1\n");}return 0;}
- FOJ Playing with Calculator (模运算)
- foj 1017 Playing with Calculator
- FZU_1017 Playing with Calculator
- zoj1537- Playing with a Calculator
- ZOJ Problem Set - 1537(Playing with a Calculator)
- FOJ 1339 Calculator
- FOJ 2036 Log Calculator
- FOJ--1339--Calculator--解题报告
- Playing with DataGrid Control
- Playing with ptrace
- Playing with the Stack
- Playing with the Stack
- Playing with the stack
- playing with ptrace
- Playing with Virtual Memory
- 10067 - Playing with Wheels
- Playing with Virtual Memory
- 110902 Playing with Wheels
- UVA - 10305 Ordering Tasks
- HDU 3652 B-number(数位DP)
- Java.net包死缠烂看
- 接口测试自动化生成框架
- 1051. Pop Sequence (25)-PAT甲级真题(栈模拟)
- FOJ Playing with Calculator (模运算)
- 删除所有无效的 DedeCms 标签Tag方法
- 下拉列表级联菜单封装(直接拿来使用)
- 笔记:发送邮件激活账户实现
- MapReduce实现词频统计
- 运行发布商品后,查看结果树中,有:提交错误,修改后又无效门店ID,
- English Daily-August 15,2016 -Letty
- 【BZOJ 2144】【JZOJ 4701】Throw
- APP开发实战128-APP Log功能设计