#abc324d. D - Square Permutation
D - Square Permutation
Score : points
问题描述
给定一个长度为 的由数字组成的字符串 。
通过将 的一个排列解释为十进制整数,找出可以得到的完全平方数的数量。
更形式化地表述如下:
令 表示 中从开始算起第 个数字对应的数值 。
求解满足以下条件的完全平方数的数量:存在一个 的排列 ,使得该完全平方数可以表示为 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a string of length consisting of digits.
Find the number of square numbers that can be obtained by interpreting a permutation of as a decimal integer.
More formally, solve the following.
Let be the number corresponding to the -th digit from the beginning of .
Find the number of square numbers that can be represented as $\displaystyle \sum _ {i=1} ^ N s _ {p _ i}10 ^ {N-i}$ with a permutation of .
Constraints
- is a string of length consisting of digits.
- is an integer.
Input
The input is given from Standard Input in the following format:
Output
Print the answer in a single line.
Sample Input 1
4
4320
Sample Output 1
2
For , we have $s _ 4\times10 ^ 3+s _ 2\times10 ^ 2+s _ 3\times10 ^ 1+s _ 1=324=18 ^ 2$.
For , we have $s _ 3\times10 ^ 3+s _ 2\times10 ^ 2+s _ 4\times10 ^ 1+s _ 1=2304=48 ^ 2$.
No other permutations result in square numbers, so you should print .
Sample Input 2
3
010
Sample Output 2
2
For or , we have $\displaystyle\sum _ {i=1} ^ Ns _ {p _ i}10 ^ {N-i}=1=1 ^ 2$.
For or , we have $\displaystyle\sum _ {i=1} ^ Ns _ {p _ i}10 ^ {N-i}=100=10 ^ 2$.
No other permutations result in square numbers, so you should print . Note that different permutations are not distinguished if they result in the same number.
Sample Input 3
13
8694027811503
Sample Output 3
840
update @ 2024/3/10 01:46:17