Number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2159    Accepted Submission(s): 614

Problem Description
  Here are two numbers A and B (0 < A <= B). If B cannot be divisible by A, and A and B are not co-prime numbers, we define A as a special number of B.
  For each x, f(x) equals to the amount of x’s special numbers.
  For example, f(6)=1, because 6 only have one special number which is 4. And f(12)=3, its special numbers are 8,9,10.
  When f(x) is odd, we consider x as a real number.
  Now given 2 integers x and y, your job is to calculate how many real numbers are between them.
 
Input
  In the first line there is an integer T (T <= 2000), indicates the number of test cases. Then T line follows, each line contains two integers x and y (1 <= x <= y <= 2^63-1) separated by a single space.
 
Output
  Output the total number of real numbers.
 
Sample Input
2
1 1
1 10
Sample Output
0
4
 
这道题,同样的没有思路的题目。
有的人说,1000ms,题目复杂,就想到是找规律了。这规律.....。
1->x : ans
            1-1:0
            1-2:0
            1-3:0
            1-4:0
            1-5:0//x小于等于5之前都是0。5/2-2 = 0
            1-6:1//x是某个数的平方和,且k为偶数。则不变 6/2-2 = 1;
            1-7:1//x是某个数的平方和,且k为偶数。则不变 7/2-2 = 1;
            1-8:2    
            1-9:3//x是某个数k的平方和,且k为奇数。加1  9/3-2 + 1 = 3;
            1-10:4
            1-11:4
            1-12:5
            1-13:5
            1-14:6//x是某个数k的平方和,且k为奇数。加1  14/2-2 + 1 = 6;
            1-15:6
            1-16:6//x是某个数k的平方和,且k为偶数。则不变  16/2-2 = 6;
            1-17:6
            1-18:6
            1-19:7
            1-20:8
            1-21:8
            1-22:9
            1-23:9
            1-24:10
            1-25:11//x是某个数k的平方和,且k为奇数。加1   25/2 -2 + 1 = 11;
            1-26:12
还有考虑区间的问题求的是[n,m]=[1,m]-[1,n-1];
  1. /*
  2. 我只能说,以后遇到复杂度高,
  3. 时间小的题目
  4. 找规律是一种切入方式
  5.  
  6. */
  7.  
  8. #include<stdio.h>
  9. #include<math.h>
  10. #include<stdlib.h>
  11.  
  12. __int64 make_ini(__int64 num)
  13. {
  14. __int64 tmp=num;
  15. if(num<)
  16. return ;
  17. tmp=(num>>)-;
  18. num=(__int64)sqrt(num*1.0);
  19. if(num%==)
  20. tmp++;
  21. return tmp;
  22. }
  23.  
  24. int main()
  25. {
  26. __int64 T,n,m;
  27. while(scanf("%I64d",&T)>)
  28. {
  29. while(T--)
  30. {
  31. scanf("%I64d%I64d",&n,&m);
  32. printf("%I64d\n",make_ini(m)-make_ini(n-));
  33. }
  34. return ;
  35. }
  36. return ;
  37. }

HDU 4279 Number-------找规律题的更多相关文章

  1. HDU 4279 Number(找规律)

    Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  2. HDU 2086 A1 = ? (找规律推导公式 + 水题)(Java版)

    Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2086 ——每天在线,欢迎留言谈论. 题目大意: 有如下方程:Ai = (Ai-1 ...

  3. hdu 5047 大数找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=5047 找规律 信kuangbin,能AC #include <stdio.h> #include & ...

  4. Codeforces 959E. Mahmoud and Ehab and the xor-MST 思路:找规律题,时间复杂度O(log(n))

    题目: 解题思路 这题就是0,1,2...n-1总共n个数字形成的最小生成树. 我们可以发现,一个数字k与比它小的数字形成的异或值,一定可以取到k与所有正整数形成的异或值的最小值. 要计算n个数字的情 ...

  5. hdu 4279 Number(G++提交)

    打表找规律: #include<stdio.h> #include<math.h> #define N 250 bool judge(int i,int j) { ;k< ...

  6. HDU 4279 Number(2012天津网络游戏---数论分析题)

    转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接:pid=4279">http://acm.hdu.edu ...

  7. hdu 4455 Substrings(找规律&DP)

    Substrings Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  8. HDU 4279 Number 坑爹的迷之精度

    题目描述 首先定义"special number": 如果对于一个数字B,存在一个数字A(0<A<=B),并同时满足 B%A=0 和 gcd(A,B) != 1 ,那么 ...

  9. hdu 5106 组合数学+找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=5106 给定n和r,要求算出[0,r)之间所有n-onebit数的和,n-onebit数是所有数位中1的个数. 对 ...

  10. hdu 4759 大数+找规律 ***

    题目意思很简单. 就是洗牌,抽出奇数和偶数,要么奇数放前面,要么偶数放前面. 总共2^N张牌. 需要问的是,给了A X B Y  问经过若干洗牌后,第A个位置是X,第B个位置是Y 是不是可能的. Ja ...

随机推荐

  1. redis所有数据结构及对象------redis设计与实现

    建议点开原图看

  2. jvm(2)类的初始化(二)和实例化

    深入理解Java对象的创建过程:类的初始化与实例化 对象实例化内存分析: 对内存分配情况分析最常见的示例便是对象实例化: Object obj = new Object(); 这段代码的执行会涉及ja ...

  3. crop和resize操作区别

    crop:对图像进行剪切 resize:对图像进行伸缩 实践代码 import cv2 bb2d = [30, 30, 72 ,42] image = cv2.imread('car.png') pt ...

  4. iOS 获取设备的各种信息的方法

    一.目录结构: 获取屏幕宽度与高度 获取设备版本号 获取iPhone名称 获取app版本号 获取电池电量 获取当前系统名称 获取当前系统版本号 获取通用的唯一识别码UUID 获取当前设备IP 获取总内 ...

  5. VSTO学习(六)——创建Outlook解决方案

    本专题概要 引言 Outlook对象模型 自定义Outlook窗体 小结 一.引言 在上一个专题中,为大家简单介绍了下如何创建Word解决方案的,所以本专题中将为大家介绍下Outlook相关的内容.我 ...

  6. error 'there is already an open datareader associated with this command which must be closed first'

    This can be easily solved by allowing MARS in your connection string. Add MultipleActiveResultSets=t ...

  7. Java之集合(二十五)ConcurrentHashMap

    转载请注明源出处:http://www.cnblogs.com/lighten/p/7520808.html 1.前言 本章介绍使用的最频繁的并发集合类之一ConcurrentHashMap,之前介绍 ...

  8. java8新特性-入门摘要

    本文是针对java8做的入门摘要笔录,详细分析可参见如下原文. 原文地址 http://www.javacodegeeks.com/2013/02/java-8-from-permgen-to-met ...

  9. tomcat启动(三)Catalina分析-load方法分析

    load()方法按从上到下顺序分析(主要分析本人所没学过的知识点,其它略过...). Digester类作用 使用sax技术对xml进行解析 未开始解析时Digester.push(this)这个用来 ...

  10. WPF获取相对位置、坐标的方法

    1.获取鼠标在控件中的坐标: private void item_MouseDown(object sender, MouseButtonEventArgs e) { Point point = e. ...