|
发表于 2020-4-9 20:07:16
|
显示全部楼层
本帖最后由 代号-K 于 2020-4-9 20:12 编辑
110 的 answer is : 1260
由于 n 的 可拆解 为 n^2 中 两个因数的乘积
所以可以编写代码如下:
- void getDiophantineReciprocals(int flag){
- int num = 1;
- int count;
- int i;
- ElementType numPow;
- while(true){
- count = 1;
- i = 2;
- num++;
- numPow = (ElementType) pow(num, 2);
- while(i <= num){
- if(numPow % i == 0){
- count++;
- }
- i++;
- }
- if(count >= flag){
- printf("get it\n");
- printf("%d has %d\n", num,count);
- return;
- }
- printf("%d has %d\n",num,count);
- }
- }
- int main(int argc, char *argv[]){
- getDiophantineReciprocals(110);
- return 0;
- }
复制代码
|
|