### Saratov State University :: Online Contester

::Go
- home
- news
- register
 - update personal info
 - problemset archive
- submit
- status online
- standing
- contests
- virtual contests
- forum
- statistic
- FAQ
- projects

 ::Poll Are you registered on Codeforces?YesNoWhat is it???[results]

::webboard

 WA On test 4 , why?
ID: 045970
Problem: 502
Contest: 0
Date: 2011-11-07 18:49:15

Hi , why i am getting WA on test 4?

First i will get n ; then i will push back digits to a vectore . After that i sort the vecotre and then use next permutation , then in a while which will finish after there is no next permutation, it check if the number %17==0

//502. Digits Permutation

#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> ans;
int main() {
unsigned long long n;
cin>>n;
while(n>0){
ans.push_back(n%10);
n/=10;
}
sort(ans.begin(),ans.end());
int size=ans.size();
do{
unsigned long long z=0;
for(int i=0;i<size;i++){
int a=1;
for(int j=1;j<=i;j++)
a*=10;
z+=a*ans[i];
}

if(z%17==0){
cout<<z;
return 0;
}
}while(next_permutation(ans.begin(),ans.end()));

cout<<-1<<endl;

return 0;
}