CF-375A Divisible by Seven
来源:互联网 发布:马鞍山市网络推广总监 编辑:程序博客网 时间:2024/04/29 13:43
只要想到了就很容易了,由于7是个素数,它的余数0~6,那么我们只需要把1,6,8,9,前面不过多小数,其余数必定在(0~6),所以任意排序(1,6,8,9)满足加上(0~6)的余数能被7整除就行了,这就靠自己与凑了。
#include<iostream>#include<cstdio>#include<cstring>using namespace std ;int cnt[10];const int num[]={1869,1896,1986,1698,6198,1689,1968};char st[1000005];int main(){ while(scanf("%s",st)!=EOF){int len=strlen(st);memset(cnt,0,sizeof(cnt));for(int i=0;i<len;i++){cnt[st[i]-'0']++;}cnt[1]--;cnt[6]--;cnt[8]--;cnt[9]--;int carry=0;for(int i=1;i<=9;i++){for(int j=0;j<cnt[i];j++){putchar(i+'0');carry=(carry*10+i)%7;}}carry=carry*10000%7;printf("%d",num[carry%7]);for(int i=0;i<cnt[0];i++) putchar('0');puts(""); } return 0 ;}
0 0
- CF-375A Divisible by Seven
- CodeForces 375A Divisible By Seven
- CodeForces 375A Divisible by Seven
- CodeForces 375A Divisible by Seven
- CodeForces 374A. Divisible by Seven
- CF 376C Divisible By Seven 同余+暴力
- Divisible by Seven
- C. Divisible by Seven
- Divisible by Seven CodeForces
- A. Divisible by Seven----打表暴力/数学思维
- codeforce 221 Div2 C - Divisible by Seven
- Code forces 376 C Divisible by Seven
- Codeforces Round #221 (Div. 2)-C. Divisible by Seven
- codeforces 376C Divisible by Seven(能被7整除的数)
- Codeforces Round #221 (Div. 2) B. I.O.U. C. Divisible by Seven D. Maximum Submatrix 2 解题报告
- how many positive integers are divisible by a number d in range [x,y]?
- 问题 B: Divisible by 3
- CF 375A
- 服务端开发,一些常见的专业术语
- cocos2dx继承结构图
- Android 传感器分析之Driver层(轮寻方式)
- iOS with ffmpeg
- 归并排序的学习
- CF-375A Divisible by Seven
- Android之Notification的多种用法
- HBase学习笔记(三)
- Android Nand Flash 分区
- 2013年11月13日星期三(DEMO8_9,三角形光栅化)
- android-office-demo
- Zigbee相关资料大全,不断更新中……
- 数据库设计说明书——机房收费系统
- 托管代码与非托管代码之间的封送处理