原题地址:http://codeforces.com/contest/375/problem/A
题意:
略
题解
构造,数论
#include<bits/stdc++.h> #define clr(x,y) memset((x),(y),sizeof(x)) using namespace std; typedef long long LL; const int maxn=1e6; char s[maxn+5]; vector <int> v={1,6,8,9}; int A[10]; int Count[10]; int main(void) { #ifdef ex freopen ("../in.txt","r",stdin); //freopen ("../out.txt","w",stdout); #endif scanf("%s",s); int len=strlen(s); for (int i=0;i<len;++i) ++Count[s[i]-'0']; --Count[1]; --Count[6]; --Count[8]; --Count[9]; do { //cout<<v[0]<<' '<<v[1]<<endl; int tmp=0; for (int i=0;i<=3;++i) tmp=tmp*10+v[i]; /*****/ A[tmp%7]=tmp; }while (next_permutation(v.begin(),v.end())); /*****/ int tmp=0; for (int i=1;i<=9;++i) { for (int j=1;j<=Count[i];++j) { printf("%d",i); tmp=(tmp*10+i)%7; /*****/ } } tmp=tmp*10000%7; tmp=(7-tmp)%7; /************/ printf("%d",A[tmp]); for (int i=1;i<=Count[0];++i) printf("0"); }