鱼C论坛

 找回密码
 立即注册
查看: 3827|回复: 10

题目261:平方和支点

[复制链接]
发表于 2017-1-13 17:05:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
Pivotal Square Sums

Let us call a positive integer k a square-pivot, if there is a pair of integers m > 0 and n ≥ k, such that the sum of the (m+1) consecutive squares up to k equals the sum of the m consecutive squares from (n+1) on:

(k-m)2 + ... + k2 = (n+1)2 + ... + (n+m)2

Some small square-pivots are

  • 4: 32 + 42 = 52
  • 21: 202 + 212 = 292
  • 24: 212 + 222 + 232 + 242 = 252 + 262 + 272
  • 110: 1082 + 1092 + 1102 = 1332 + 1342


Find the sum of all distinct square-pivots ≤ 1010.


题目:

我就称正整数 k 为平方支点,如果存在一对整数 m > 0 和 n ≥ k,使得到 k 为止的 (m+1) 个连续的平方的和等于从 (n+1) 开始的 m 个连续的平方的和:

(k-m)2 + ... + k2 = (n+1)2 + ... + (n+m)2.

一些小的平方支点:

  • 4:32 + 42 = 52
  • 21:202 + 212 = 292
  • 24:212 + 222 + 232 + 242 = 252 + 262 + 272
  • 110:1082 + 1092 + 1102 = 1332 + 1342


求所有 ≤ 1010 的不同的平方支点的和。


想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-1-13 21:52:44 | 显示全部楼层
跟欧拉学了一招

加了引号,无法被复制~
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-3-15 20:21:09 | 显示全部楼层
本帖最后由 99592938 于 2017-3-15 20:53 编辑
##平方支点等式化简为:(m+1)*k**2=m*n**2+m*(m+1)(n+k)
##由条件可分析:0<m<=(k-2)/2)**0.5
##循环带入k、m,可求出n值,若n>=k且为整数,则k为平方支点。
def value_n(k,m):
    l_n=[0,0]
    a=m
    b=m*(m+1)
    c=(m+1)*m*k-(m+1)*k*k
    if b*b-4*a*c<0:
        return l_n
    else:
        d=(b*b-4*a*c)**0.5
        n1=(-b+d)/(2*a)
        n2=(-b-d)/(2*a)
        if n1>=k and (n1-int(n1))==0:
            l_n[0]=int(n1)
        if n2>=k and (n2-int(n2))==0:
            l_n[1]=int(n2)
        return l_n

num = int(input('请输入范围上限:'))
dic_k={}
for k in range(2,num+1):
    for m in range(1,int(((k-2)/2)**0.5)+1):
        l_n=value_n(k,m)
        for each in l_n:
            if each:
                dic_k[k]=[m,each]
print(sum(dic_k.keys()))
#print(sorted(list(dic_k.keys())))

拿小范围数来试,程序是正确的,但拿100亿来跑~~~已经半个多小时了
>>>
请输入范围上限:110
355
[4, 12, 21, 24, 40, 60, 84, 110]
>>> ================================ RESTART ================================
>>>
请输入范围上限:10000000000
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-3-15 20:28:46 | 显示全部楼层

然而,这是网页加了限制,引号外面也不能复制,哈哈哈
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-5-14 21:02:44 | 显示全部楼层
怎么停更了呢- -
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

匿名鱼油  发表于 2017-12-3 21:12:30
去project euler官网去做吧,虽然是英文的(ω)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具

发表于 2018-11-13 04:08:18 | 显示全部楼层
100亿的话,俨然需要借助数学的方法了,这个真的不会了。
def filt1(num,twi):
    m = num**2
    for i in range(1,twi+1):
        m += (num-i)**2
    return m

def filt2(num,twi):
    m = num**2
    for i in range(1,twi):
        m += (num+i)**2
    return m

def choice(num):
    
    flag = int(((num**2) + (num-1)**2)**0.5)
    for i in range(num+1,flag+1):
        T = True
        for j in range(1,num):
            if filt1(num,j) == filt2(i,j):
                print(num,i,j)
                return True
            elif filt1(num,j) < filt2(i,j):
                break
    return False

for i in range(1,10000000):
    choice(i)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-11 13:32:24 | 显示全部楼层

不是可以复制吗……
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-1 13:07:26 | 显示全部楼层
本帖最后由 代号-K 于 2020-4-1 14:02 编辑

把公式化简一下,然后进行判断
代码附上
typedef unsigned long long ElementType;
void getSquarePivots(int num){
    int k, n, m;
    int flag;
    ElementType sum = 0, tmp;
    for(k = 1; k <= num; k++){
        for(m = 1; m <= k; m++){
            flag = (int) (pow((m+1)*1.0/m, 0.5) * k);
            tmp = pow(k-m,2);
            if(tmp % m == 0){
            for(n = k; n <= flag - 1; n++){
                if(tmp == (ElementType)((n-k+m)*(n+1+k)*m)){
                    printf("k:%d, m:%d, n:%d\n",k,m,n);
                    sum+= k;
                }
            }
            }
        }
    }
    printf("result is follow\n");
    printf("%lld\n",sum);
}
int main(int argc, char *argv[]){
    //ElementType ret = -1;
    getSquarePivots(100000);
    return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-1 13:49:21 | 显示全部楼层
跑代码,发现个大密秘
当且仅当 n==k 时 m 是递增的
k:4, m:1, n:4
k:12, m:2, n:12
k:24, m:3, n:24
k:40, m:4, n:40
k:60, m:5, n:60
k:84, m:6, n:84
k:112, m:7, n:112
k:144, m:8, n:144
k:180, m:9, n:180
k:220, m:10, n:220
k:264, m:11, n:264
k:312, m:12, n:312
k:364, m:13, n:364
k:420, m:14, n:420
k:480, m:15, n:480
k:544, m:16, n:544
k:612, m:17, n:612
k:684, m:18, n:684
k:760, m:19, n:760
k:840, m:20, n:840
k:924, m:21, n:924
k:1012, m:22, n:1012
k:1104, m:23, n:1104
k:1200, m:24, n:1200
k:1300, m:25, n:1300
k:1404, m:26, n:1404
k:1512, m:27, n:1512
k:1624, m:28, n:1624
k:1740, m:29, n:1740
k:1860, m:30, n:1860
k:1984, m:31, n:1984
k:2112, m:32, n:2112
k:2244, m:33, n:2244
k:2380, m:34, n:2380
k:2520, m:35, n:2520
k:2664, m:36, n:2664
k:2812, m:37, n:2812
k:2964, m:38, n:2964
k:3120, m:39, n:3120
k:3280, m:40, n:3280
k:3444, m:41, n:3444
k:3612, m:42, n:3612
k:3784, m:43, n:3784
k:3960, m:44, n:3960
k:4140, m:45, n:4140
k:4324, m:46, n:4324
k:4512, m:47, n:4512
k:4704, m:48, n:4704
k:4900, m:49, n:4900
k:5100, m:50, n:5100
k:5304, m:51, n:5304
k:5512, m:52, n:5512
k:5724, m:53, n:5724
k:5940, m:54, n:5940
k:6160, m:55, n:6160
k:6384, m:56, n:6384
k:6612, m:57, n:6612
k:6844, m:58, n:6844
k:7080, m:59, n:7080
k:7320, m:60, n:7320
k:7564, m:61, n:7564
k:7812, m:62, n:7812
k:8064, m:63, n:8064
k:8320, m:64, n:8320
k:8580, m:65, n:8580
k:8844, m:66, n:8844
k:9112, m:67, n:9112
k:9384, m:68, n:9384
k:9660, m:69, n:9660
k:9940, m:70, n:9940
k:10224, m:71, n:10224
k:10512, m:72, n:10512
k:10804, m:73, n:10804
k:11100, m:74, n:11100
k:11400, m:75, n:11400
k:11704, m:76, n:11704
k:12012, m:77, n:12012
k:12324, m:78, n:12324
k:12640, m:79, n:12640
k:12960, m:80, n:12960
k:13284, m:81, n:13284
k:13612, m:82, n:13612
k:13944, m:83, n:13944
k:14280, m:84, n:14280
k:14620, m:85, n:14620
k:14964, m:86, n:14964
k:15312, m:87, n:15312
k:15664, m:88, n:15664
k:16020, m:89, n:16020
k:16380, m:90, n:16380
k:16744, m:91, n:16744
k:17112, m:92, n:17112
k:17484, m:93, n:17484
k:17860, m:94, n:17860
k:18240, m:95, n:18240
k:18624, m:96, n:18624
k:19012, m:97, n:19012
k:19404, m:98, n:19404
k:19800, m:99, n:19800
k:20200, m:100, n:20200
k:20604, m:101, n:20604
k:21012, m:102, n:21012
k:21424, m:103, n:21424
k:21840, m:104, n:21840
k:22260, m:105, n:22260
k:22684, m:106, n:22684
k:23112, m:107, n:23112
k:23544, m:108, n:23544
k:23980, m:109, n:23980
k:24420, m:110, n:24420
k:24864, m:111, n:24864
k:25312, m:112, n:25312
k:25764, m:113, n:25764
k:26220, m:114, n:26220
k:26680, m:115, n:26680
k:27144, m:116, n:27144
k:27612, m:117, n:27612
k:28084, m:118, n:28084
k:28560, m:119, n:28560
k:29040, m:120, n:29040
k:29524, m:121, n:29524
k:30012, m:122, n:30012
k:30504, m:123, n:30504
k:31000, m:124, n:31000
k:31500, m:125, n:31500
k:32004, m:126, n:32004
k:32512, m:127, n:32512
k:33024, m:128, n:33024
k:33540, m:129, n:33540
k:34060, m:130, n:34060
k:34584, m:131, n:34584
k:35112, m:132, n:35112
k:35644, m:133, n:35644
k:36180, m:134, n:36180
k:36720, m:135, n:36720
k:37264, m:136, n:37264
k:37812, m:137, n:37812
k:38364, m:138, n:38364
k:38920, m:139, n:38920
k:39480, m:140, n:39480
k:40044, m:141, n:40044
k:40612, m:142, n:40612
k:41184, m:143, n:41184
k:41760, m:144, n:41760
k:42340, m:145, n:42340
k:42924, m:146, n:42924
k:43512, m:147, n:43512
k:44104, m:148, n:44104
k:44700, m:149, n:44700
k:45300, m:150, n:45300
k:45904, m:151, n:45904
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-1 13:57:35 | 显示全部楼层
这是正常跑下来的,只能跑到151不知道怎么回事,可能电脑问题吧
k:4, m:1, n:4
k:12, m:2, n:12
k:21, m:1, n:28
k:24, m:3, n:24
k:40, m:4, n:40
k:60, m:5, n:60
k:84, m:6, n:84
k:110, m:2, n:132
k:112, m:7, n:112
k:120, m:1, n:168
k:144, m:8, n:144
k:180, m:9, n:180
k:220, m:10, n:220
k:264, m:11, n:264
k:312, m:12, n:312
k:315, m:3, n:360
k:364, m:13, n:364
k:420, m:14, n:420
k:480, m:15, n:480
k:544, m:16, n:544
k:612, m:17, n:612
k:684, m:4, n:760
k:684, m:18, n:684
k:697, m:1, n:984
k:760, m:19, n:760
k:820, m:8, n:861
k:840, m:20, n:840
k:924, m:21, n:924
k:1012, m:22, n:1012
k:1080, m:2, n:1320
k:1104, m:23, n:1104
k:1200, m:24, n:1200
k:1265, m:5, n:1380
k:1300, m:25, n:1300
k:1404, m:26, n:1404
k:1512, m:27, n:1512
k:1624, m:28, n:1624
k:1740, m:29, n:1740
k:1860, m:30, n:1860
k:1984, m:31, n:1984
k:2106, m:6, n:2268
k:2112, m:32, n:2112
k:2244, m:33, n:2244
k:2380, m:34, n:2380
k:2520, m:35, n:2520
k:2664, m:36, n:2664
k:2812, m:37, n:2812
k:2964, m:38, n:2964
k:3120, m:39, n:3120
k:3255, m:7, n:3472
k:3280, m:40, n:3280
k:3444, m:41, n:3444
k:3612, m:42, n:3612
k:3784, m:43, n:3784
k:3960, m:44, n:3960
k:4060, m:1, n:5740
k:4140, m:45, n:4140
k:4324, m:46, n:4324
k:4368, m:3, n:5040
k:4512, m:47, n:4512
k:4704, m:48, n:4704
k:4760, m:8, n:5040
k:4900, m:49, n:4900
k:5100, m:50, n:5100
k:5304, m:51, n:5304
k:5512, m:52, n:5512
k:5724, m:53, n:5724
k:5940, m:54, n:5940
k:6160, m:55, n:6160
k:6384, m:56, n:6384
k:6612, m:57, n:6612
k:6669, m:9, n:7020
k:6844, m:58, n:6844
k:7080, m:59, n:7080
k:7320, m:60, n:7320
k:7564, m:61, n:7564
k:7812, m:62, n:7812
k:8064, m:63, n:8064
k:8320, m:64, n:8320
k:8580, m:65, n:8580
k:8844, m:66, n:8844
k:9030, m:10, n:9460
k:9112, m:67, n:9112
k:9384, m:68, n:9384
k:9660, m:69, n:9660
k:9940, m:70, n:9940
k:10224, m:71, n:10224
k:10512, m:72, n:10512
k:10682, m:2, n:13080
k:10804, m:73, n:10804
k:11100, m:74, n:11100
k:11400, m:75, n:11400
k:11704, m:76, n:11704
k:11772, m:24, n:11990
k:11891, m:11, n:12408
k:12012, m:77, n:12012
k:12240, m:4, n:13680
k:12324, m:78, n:12324
k:12640, m:79, n:12640
k:12960, m:80, n:12960
k:13284, m:81, n:13284
k:13612, m:82, n:13612
k:13944, m:83, n:13944
k:14280, m:84, n:14280
k:14620, m:85, n:14620
k:14964, m:86, n:14964
k:15300, m:12, n:15912
k:15312, m:87, n:15312
k:15664, m:88, n:15664
k:16020, m:89, n:16020
k:16380, m:90, n:16380
k:16744, m:91, n:16744
k:17112, m:92, n:17112
k:17484, m:93, n:17484
k:17860, m:94, n:17860
k:18240, m:95, n:18240
k:18624, m:96, n:18624
k:19012, m:97, n:19012
k:19305, m:13, n:20020
k:19404, m:98, n:19404
k:19800, m:99, n:19800
k:20200, m:100, n:20200
k:20604, m:101, n:20604
k:21012, m:102, n:21012
k:21424, m:103, n:21424
k:21840, m:104, n:21840
k:22260, m:105, n:22260
k:22684, m:106, n:22684
k:23112, m:107, n:23112
k:23544, m:108, n:23544
k:23661, m:1, n:33460
k:23954, m:14, n:24780
k:23980, m:109, n:23980
k:24420, m:110, n:24420
k:24864, m:111, n:24864
k:25312, m:112, n:25312
k:25764, m:113, n:25764
k:26220, m:114, n:26220
k:26680, m:115, n:26680
k:27144, m:116, n:27144
k:27612, m:117, n:27612
k:27720, m:5, n:30360
k:27724, m:8, n:29397
k:28084, m:118, n:28084
k:28441, m:49, n:28680
k:28560, m:119, n:28560
k:29040, m:120, n:29040
k:29295, m:15, n:30240
k:29524, m:121, n:29524
k:30012, m:122, n:30012
k:30504, m:123, n:30504
k:31000, m:124, n:31000
k:31500, m:125, n:31500
k:32004, m:126, n:32004
k:32512, m:127, n:32512
k:33024, m:128, n:33024
k:33540, m:129, n:33540
k:34060, m:130, n:34060
k:34584, m:131, n:34584
k:35112, m:132, n:35112
k:35376, m:16, n:36448
k:35644, m:133, n:35644
k:36180, m:134, n:36180
k:36720, m:135, n:36720
k:37264, m:136, n:37264
k:37812, m:137, n:37812
k:38364, m:138, n:38364
k:38920, m:139, n:38920
k:39480, m:140, n:39480
k:40044, m:141, n:40044
k:40612, m:142, n:40612
k:41184, m:143, n:41184
k:41760, m:144, n:41760
k:42245, m:17, n:43452
k:42340, m:145, n:42340
k:42924, m:146, n:42924
k:43512, m:147, n:43512
k:44104, m:148, n:44104
k:44700, m:149, n:44700
k:45300, m:150, n:45300
k:45904, m:151, n:45904
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-12-22 18:17

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表