1 条题解
-
0
C :
#include <stdio.h> #include <stdbool.h> #include <math.h> bool has_unique_digits(long long n); int main() { long long min = ceil(sqrt(100000000)); long long max = floor(sqrt(999999999)); for (long long x = min; x <= max; x++) { long long square = x * x; if (has_unique_digits(square)) { printf("%lld\n", x); } } return 0; } bool has_unique_digits(long long n) { int digits[10] = { 0 }; int count = 0; while (n > 0) { int digit = n % 10; if (digits[digit] > 0) return false; digits[digit]++; n /= 10; count++; if (count > 9) return false; } return true; }C++ :
#include <bits/stdc++.h> #define int long long using namespace std; const int N=1e6+10; int nums[15]; void solve() { for(int i=10000;i<=35000;i++){ for(int q=0;q<10;q++) nums[q]=0; int a=i*i; if(a>999999999) break; for(int j=1;j<=100000000;j*=10){ nums[a/j%10]++; } for(int j=0;j<=10;j++){ if(nums[j]>1) break; if(j==10) cout<<i<<" "; } } } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; t=1; while(t--) { solve(); } return 0; }
- 1
信息
- ID
- 684
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 10
- 标签
- 提交数
- 25
- 已通过
- 0
- 上传者