Friends number NBUT - 1223 (暴力打表)
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.
//对5000000之内的每个数的所有因子暴力打表求和竟然不会超时,我擦。。。很强
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<cstdio>
#include<sstream>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include <ctype.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std;
typedef long long ll;
const int maxn=11000;
const int INF=0x3f3f3f3f;
int f[5000010];
int xA[200],xB[200];
int main()
{
    for(int i=1; i<=5000000; i++)//暴力打表,把每个数的所以因子的和求出来
    {
        int xsk=i+i;
        while(xsk<=5000000)
        {
            f[xsk]+=i;//f函数存储的是每个数所以因子的和
            xsk+=i;
        }
    }
    int sum=0;
    for(int i=1; i<=5000000; i++)
    {
        int A=i,B=f[i];
        if(B>A&&B<5000000&&f[B]==i)
        {
            xA[sum]=A;
            xB[sum]=B;
            sum++;
        }
    }
    int L,R;
    while(~scanf("%d%d",&L,&R))
    {
        int ans=0;
        for(int i=0; i<sum; i++)
        {
            if(xA[i]>=L&&xA[i]<=R&&xB[i]>=L&&xB[i]<=R) ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}
Friends number NBUT - 1223 (暴力打表)的更多相关文章
- XTU OJ 1210 Happy Number (暴力+打表)
		
Problem Description Recently, Mr. Xie learn the concept of happy number. A happy number is a number ...
 - NBUT 1223 Friends number 2010辽宁省赛
		
Time limit 1000 ms Memory limit 131072 kB Paula and Tai are couple. There are many stories betwee ...
 - HDU 5179 beautiful number (数位dp / 暴力打表 / dfs)
		
beautiful number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
 - 【ZOJ】3785 What day is that day?  ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用
		
转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...
 - HDU 1216 Assistance Required(暴力打表)
		
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1216 Assistance Required Time Limit: 2000/1000 MS (Ja ...
 - ACM/ICPC 之 暴力打表(求解欧拉回路)-编码(POJ1780)
		
///找到一个数字序列包含所有n位数(连续)一次且仅一次 ///暴力打表 ///Time:141Ms Memory:2260K #include<iostream> #include< ...
 - HDU 1012 u Calculate e【暴力打表,水】
		
u Calculate e Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
 - Codeforces 914 C 数位DP+暴力打表+思维
		
题意 给出一个二进制数\(n\),每次操作可以将一个整数\(x\)简化为\(x\)的二进制表示中\(1\)的个数,如果一个数简化为\(1\)所需的最小次数为\(k\),将这个数叫做特殊的数, 问从\( ...
 - 暴力打表之hdu 2089
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 有两种方法: 1.数位DP算法 2.暴力打表——真是个好法子!!! 接下来是注意点: 1.一般这 ...
 
随机推荐
- JS练习题(左侧菜单下拉+好友选中)
			
题一.左侧菜单下拉 做题思路:先做菜单和子菜单,把子菜单默认隐藏.再用JS调样式. <style type="text/css"> *{ margin:0px auto ...
 - 【洛谷 P3628】 [APIO2010]特别行动队 (斜率优化)
			
题目链接 斜率优化总结待补,请催更.不催更不补 \[f[i]=f[j]+a*(sum[i]-sum[j])^2+b*(sum[i]-sum[j])+c\] \[=f[j]+a*sum[i]^2+a*s ...
 - Bazinga(HDU5510+KMP)
			
t题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5510 题目: 题意:找到一个编号最大的字符串满足:存在一个编号比它小的字符串不是它的字串. 思路:K ...
 - jQuery mobile 滑动打开面板
			
一.首先在<head></head>里面引入jQuery库.jQuery mobile库以及jQuery mobile样式 <link rel="stylesh ...
 - js_在原有的日期上添加天数输出添加后的日期
			
开始编码工作也有段时间了,想想没有留下点什么,有点遗憾.学到的一些经验,写写,分享一下.也给自己整理一下. 今天分享一下,在原有的日期上添加天数输出添加后的日期.开始做的时候,简单的思路是,直接用ne ...
 - new操作符(翻译自mozilla.org)
			
翻译自:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new new操作符可以实例化一个用户自 ...
 - css 背景透明,文字不透明
			
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
 - webpack版本1与版本2的若干写法区别
			
2.x的环境遇到类似this._init is not a function的报错. 版本1.x的写法: resolve: { extensions: ['', '.js', '.vue'] }, m ...
 - %和format 细说
			
Python中格式化字符串目前有两种阵营:%和format,我们应该选择哪种呢? 自从Python2.6引入了format这个格式化字符串的方法之后,我认为%还是format这根本就不算个问题.不信你 ...
 - in_device结构和in_ifaddr结构
			
/* ip配置块 */ struct in_device { /* 二层设备 */ struct net_device *dev; /* 引用计数 */ atomic_t refcnt; /* 是否正 ...