加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

Ural1209(数学推导)

发布时间:2020-12-13 20:04:39 所属栏目:PHP教程 来源:网络整理
导读:题目链接:点击打开链接 解题思路: 此题甚好。推导公式,首先视察序列110100100010000?????,我们把为1的下标单独拿出来看。顺次为1、2、4 、7、 11?????,可以分解为1(0) 、1(01)、1(012)、1(0123)、1(01234),可以推导出规律1 x * (x - 1) / 2。 那末对每

题目链接:点击打开链接


解题思路:

此题甚好。推导公式,首先视察序列110100100010000?????,我们把为1的下标单独拿出来看。顺次为1、2、4 、7、 11?????,可以分解为1+(0) 、1+(0+1)、1+(0+1+2)、1+(0+1+2+3)、1+(0+1+2+3+4),可以推导出规律1 + x * (x - 1) / 2。

那末对每一个n,我们只要判断是不是存在x使n == 1 + x * (x - 1) / 2便可。对最后判断开根号是不是为整数的判断方法,我们可以用temp - (int)temp == 0来判断,此法甚妙!


完全代码:

#include <algorithm> #include <iostream> #include <cstring> #include <climits> #include <cstdio> #include <string> #include <cmath> #include <map> #include <queue> using namespace std; typedef long long LL; const int MOD = int(1e9)+7; const int INF = 0x3f3f3f3f; const double EPS = 1e⑼; const double PI = acos(⑴.0); //M_PI; const int maxn = 700001; int ans[maxn]; int main() { #ifdef DoubleQ freopen("in.txt","r",stdin); #endif int T; cin >> T; LL n; int cnt = 0; for(int i = 0 ; i < T ; i ++) { cin >> n; double temp = sqrt(1 + 8 * (n - 1)); if(temp - (int)temp == 0) ans[cnt++] = 1; else ans[cnt++] = 0; } for(int i = 0 ; i < cnt ; i ++) printf("%d%s",ans[i],i == cnt - 1 ? " " : " "); }


更多精彩请访问:点击打开链接

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读