标签:include mat class 数列 return img 小米 -- print
#include<stdio.h> #include<math.h> int main(){ long long n,m,i,x,s; int arr[16] = {2,1,2,3,4,5,6,7,8,9,8,7,6,5,4,3}; scanf("%lld",&n); m = sqrt(2*n);///等差数列求和:sn = (a1+an)*n/2; for(i = m; i >= 0; i--) if(i*(i+1)<2*n)///等差数列 { x = i;///找出上一项 break; } s = n - (x+1)*x/2;///当前项的sn减去前一项sn就是当前项 printf("%d\n",arr[s%16]); return 0; }
标签:include mat class 数列 return img 小米 -- print
原文地址:https://www.cnblogs.com/wszhu/p/12821127.html