NBUT 1223 Friends number (打表)

2024-02-23 21:59
文章标签 打表 number friends nbut 1223

本文主要是介绍NBUT 1223 Friends number (打表),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

  • [1223] Friends number

  • 时间限制: 1000 ms 内存限制: 131072 K
  • 问题描述
  •  

    Paula and Tai are couple. There are many stories between them. The day Paula left by airplane, Tai send one message to telephone 2200284, then, everything is changing… (The story in “the snow queen”).

     

    After a long time, Tai tells Paula, the number 220 and 284 is a couple of friends number, as they are special, all divisors of 220’s sum is 284, and all divisors of 284’s sum is 220. Can you find out there are how many couples of friends number less than 10,000. Then, how about 100,000, 200,000 and so on.

     

    The task for you is to find out there are how many couples of friends number in given closed interval [a,b]。

     

     

     

     

     

     

     

     

     

  • 输入
  • There are several cases.
    Each test case contains two positive integers a, b(1<= a <= b <=5,000,000).
    Proceed to the end of file.
  • 输出
  • For each test case, output the number of couples in the given range. The output of one test case occupied exactly one line.
  • 样例输入
  • 1 100
    1 1000
  • 样例输出
  • 0
    1
  • 提示
  • 6 is a number whose sum of all divisors is 6. 6 is not a friend number, these number is called Perfect Number.
    
  • 来源
  • 辽宁省赛2010

 

题意:如果A所有因子(不包括自身)的和等于B,并且,B所有因子(不包括自身)的和等于A,则称A,B互为friend number,求给定区间有有多少对friend number

分析:这道题一开始的想法是先生成所有数的friend number ,然后O(n)查询,但是发现500W的数据很大,会TLE,所以决定打表,打表写条件的时候要注意,如果得到的数字大于500W就舍弃。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<string>
#include<iostream>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<stdlib.h>
#include<algorithm>
#define LL __int64
#define FIN freopen("in.txt","r",stdin)
using namespace std;
int a[71][2]={220,284
,1184,1210
,2620,2924
,5020,5564
,6232,6368
,10744,10856
,12285,14595
,17296,18416
,63020,76084
,66928,66992
,67095,71145
,69615,87633
,79750,88730
,100485,124155
,122265,139815
,122368,123152
,141664,153176
,142310,168730
,171856,176336
,176272,180848
,185368,203432
,196724,202444
,280540,365084
,308620,389924
,319550,430402
,356408,399592
,437456,455344
,469028,486178
,503056,514736
,522405,525915
,600392,669688
,609928,686072
,624184,691256
,635624,712216
,643336,652664
,667964,783556
,726104,796696
,802725,863835
,879712,901424
,898216,980984
,947835,1125765
,998104,1043096
,1077890,1099390
,1154450,1189150
,1156870,1292570
,1175265,1438983
,1185376,1286744
,1280565,1340235
,1328470,1483850
,1358595,1486845
,1392368,1464592
,1466150,1747930
,1468324,1749212
,1511930,1598470
,1669910,2062570
,1798875,1870245
,2082464,2090656
,2236570,2429030
,2652728,2941672
,2723792,2874064
,2728726,3077354
,2739704,2928136
,2802416,2947216
,2803580,3716164
,3276856,3721544
,3606850,3892670
,3786904,4300136
,3805264,4006736
,4238984,4314616
,4246130,4488910
,4259750,4445050
};
int main()
{int l,r;while(scanf("%d %d",&l,&r)!=EOF){int ans=0;for(int i=0;i<71;i++){if(l<=a[i][0] && r>=a[i][1])ans++;}printf("%d\n",ans);}return 0;
}
View Code

 

转载于:https://www.cnblogs.com/clliff/p/4738588.html

这篇关于NBUT 1223 Friends number (打表)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/740058

相关文章

usaco 1.2 Name That Number(数字字母转化)

巧妙的利用code[b[0]-'A'] 将字符ABC...Z转换为数字 需要注意的是重新开一个数组 c [ ] 存储字符串 应人为的在末尾附上 ‘ \ 0 ’ 详见代码: /*ID: who jayLANG: C++TASK: namenum*/#include<stdio.h>#include<string.h>int main(){FILE *fin = fopen (

uva 568 Just the Facts(n!打表递推)

题意是求n!的末尾第一个不为0的数字。 不用大数,特别的处理。 代码: #include <stdio.h>const int maxn = 10000 + 1;int f[maxn];int main(){#ifdef LOCALfreopen("in.txt", "r", stdin);#endif // LOCALf[0] = 1;for (int i = 1; i <=

uva 10916 Factstone Benchmark(打表)

题意是求 k ! <= 2 ^ n ,的最小k。 由于n比较大,大到 2 ^ 20 次方,所以 2 ^ 2 ^ 20比较难算,所以做一些基础的数学变换。 对不等式两边同时取log2,得: log2(k ! ) <=  log2(2 ^ n)= n,即:log2(1) + log2(2) + log2 (3) + log2(4) + ... + log2(k) <= n ,其中 n 为 2 ^

题目1380:lucky number

题目1380:lucky number 时间限制:3 秒 内存限制:3 兆 特殊判题:否 提交:2839 解决:300 题目描述: 每个人有自己的lucky number,小A也一样。不过他的lucky number定义不一样。他认为一个序列中某些数出现的次数为n的话,都是他的lucky number。但是,现在这个序列很大,他无法快速找到所有lucky number。既然

计蒜客 Half-consecutive Numbers 暴力打表找规律

The numbers 11, 33, 66, 1010, 1515, 2121, 2828, 3636, 4545 and t_i=\frac{1}{2}i(i+1)t​i​​=​2​​1​​i(i+1), are called half-consecutive. For given NN, find the smallest rr which is no smaller than NN

Jenkins 通过 Version Number Plugin 自动生成和管理构建的版本号

步骤 1:安装 Version Number Plugin 登录 Jenkins 的管理界面。进入 “Manage Jenkins” -> “Manage Plugins”。在 “Available” 选项卡中搜索 “Version Number Plugin”。选中并安装插件,完成后可能需要重启 Jenkins。 步骤 2:配置版本号生成 打开项目配置页面。在下方找到 “Build Env

高精度打表-Factoring Large Numbers

求斐波那契数,不打表的话会超时,打表的话普通的高精度开不出来那么大的数组,不如一个int存8位,特殊处理一下,具体看代码 #include<stdio.h>#include<string.h>#define MAX_SIZE 5005#define LEN 150#define to 100000000/*一个int存8位*/int num[MAX_SIZE][LEN];void

【Hdu】Minimum Inversion Number(逆序,线段树)

利用线段树在nlogn的时间复杂度内求一段数的逆序。 由于给的序列是由0 ~ n -1组成的,求出初始的逆序之后可以递推出移动之后的逆序数。 #include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;const in

【JavaScript】基本数据类型与引用数据类型区别(及为什么String、Boolean、Number基本数据类型会有属性和方法?)

基本数据类型   JavaScript基本数据类型包括:undefined、null、number、boolean、string。基本数据类型是按值访问的,就是说我们可以操作保存在变量中的实际的值。 1)基本数据类型的值是不可变的 任何方法都无法改变一个基本类型的值,比如一个字符串: var name = "change";name.substr();//hangconsole.log

ORA-24067: exceeded maximum number of subscribers for queue ADMIN.SMS_MT_QUEUE

临时处理办法: delete from aq$_ss_MT_tab_D;delete from aq$_ss_MT_tab_g;delete from aq$_ss_MT_tab_h;delete from aq$_ss_MT_tab_i;delete from aq$_ss_MT_tab_p;delete from aq$_ss_MT_tab_s;delete from aq$