D. Fun with Integers

链接

[http://codeforces.com/contest/1062/problem/D]

题意

给你n,让你从2到n这个区间找任意两个数,使得一个数是另一个的因子,绝对值小的可以变为绝对值大的
问你这变化过程所乘的倍数绝对值之和

分析

见过最简单的D题,直接在范围内找出倍数并保存倍数
自己看样例也就知道只是正负换了
因为会重复所不乘以4而是乘以2,看代码就知道了

代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[1000005];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	while(cin>>n){
		memset(a,0,sizeof(a));
		for(ll i=2;i*2<=n;i++)
		for(ll j=2;j*i<=n;j++)
		a[i*j]+=i+j;
		ll ans=0;
		for(ll i=4;i<=n;i++)
		ans+=2*a[i];
		cout<<ans<<endl;
	}
	return 0;
}
posted @ 2018-11-16 19:24  ChunhaoMo  阅读(341)  评论(0)    收藏  举报