0 or 1

0 or 1

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2853    Accepted Submission(s): 752


Problem Description
Solving problem is a interesting thing. Yifenfei like to slove different problem,because he think it is a way let him more intelligent. But as we know,yifenfei is weak in math. When he come up against a difficult math problem, he always try to get a hand. Now the problem is coming! Let we
define T(n) as the sum of all numbers which are positive integers can divied n. and S(n) = T(1) + T(2) + T(3)…..+T(n).
 

Input
The first line of the input contains an integer T which means the number of test cases. Then T lines follow, each line consists of only one positive integers n. You may assume the integer will not exceed 2^31.
 

Output
For each test case, you should output one lines of one integer S(n) %2. So you may see the answer is always 0 or 1 .
 

Sample Input
  
  
3 1 2 3
 

Sample Output
  
  
1 0 0
Hint
Hint S(3) = T(1) + T(2) +T(3) = 1 + (1+2) + (1+3) = 8 S(3) % 2 = 0


以此题膜拜那些用数论和打表AC的大牛们,本渣领教了 orz!!!

对于每一个数N,我们可以将其拆分为  N= p1^e1 * p2^e2 * p3^e3 * ...  * pm^em. 其中p1,p2...都是质因子,这可以回想到我们求两数的最大公约数时,我们就是将一个数拆分成质因子相乘的形式。那么首先提出一个问题,那就是数N有多少个因子了,知道排列组合的话,很快就能知道,这个结果是 K=( e1+1 )* ( e2+1 )* ... *( em+1 )因为每个质因子 pi 我们都可以取 0-ei 个来组合成一个因子,当每个都取零时,这个因子就是 1 ,当每个都去最大值时,这个因子就是 N 本身,那么如何得到这 K 个因子的和呢?我们补全 N 的质因子乘积形式,将所有质因子补全,N= 2^e1 * 3^e2 * 5^e3 * 7^e4 * 11^ e5 *......   T[N]= [ ( 2^0+2^1+...+2^e1 )*( 3^1+3^2+...+3^e2 )*...*( pm^0+pm^1+...+pm^em ) ]% 2;   我们知道 ( 2^0+2^1+...+2^e1 )% 2= 1 恒成立(因为有2^0=1),所以T[N]的值只取决与后面的乘式%2 是否出现了0,那么后面的式子怎样才会是零呢?很简单,因为所有的质素都是奇数,所以当除2以外的存在某一个质因子表达式为偶数项的时候就会为零了,也即只要满足至少存在一个 ei 的值为奇数(项数为ei- 0+ 1)。当然这题中,我们不会去直接计算为0的T[]有多少多,这很困难,而是从反面求解,即计算T[]为1的数的个数,这样,求S[N]也就转化为从1-N有多少个T[i]为1。回到前面,如果T[i]为1,那么除 2 之外所有质因子的 ei 都为偶数,这个条件就很好解决了,而不像前面的求解满足至少一项 ei 为奇数,既然除2之外所有的 ei 都为偶数,那么这个数一定会是 i= x^2 或者是 i= 2* x^2的形式。所以统计从 1-N 之间有多少个满足T[i]= 1数吧。


code:

#include <stdio.h>
#include<iostream>
using namespace std;
int a[1000];


int main()
{
    int t,i,j;
    long long ans,n;
    // init();
    scanf("%d",&t);
    while(t--)
    {
        ans=0;
        scanf("%lld",&n);
        for(long long i=1; i*i<=n; i++)
        {
            ans++;
            if(i*i*2<=n)
                ans++;
        }

        printf("%lld\n",ans%2);
    }

    return 0;
}

转载:http://www.cnblogs.com/Lyush/archive/2011/07/31/2123163.html

数学是神造的科学!!!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值