注意要排序;

next_permutation

 

prev_permutation

 

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=100;
typedef long long ll;
int T,n,d;
int a[maxn];
char s[maxn];
ll ans;
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        ans=0;
        scanf("%s",s);
        scanf("%d",&d);
        int len=strlen(s);
        for(int i=1;i<=len;i++) a[i]=s[i-1]-'0';
        sort(a+1,a+len+1);
        do
        {
            ll sum=0;
            for(int i=1;i<=len;i++)
            {
                sum=sum*10+a[i];
            }
            if(sum%d==0) ans++;
        }while(next_permutation(a+1,a+len+1));
        printf("%lld\n",ans);
    }
    
    return 0;
}
View Code

相关文章:

  • 2021-07-28
  • 2022-01-29
  • 2021-11-11
  • 2021-10-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-18
  • 2021-12-29
  • 2022-01-21
  • 2022-12-23
  • 2021-09-27
  • 2021-09-22
  • 2022-12-23
相关资源
相似解决方案