Codeforces 1062D Fun with Integers题解

Codeforces 1062D Fun with Integers题解

题意:

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

思路:

直接在范围内找出倍数并保存倍数

注意因为会出现重复的情况,所以直接乘2就好不用乘4

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define ll long long
ll a[1000010];
int main(void) {
   
	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;
}
全部评论

相关推荐

仁者伍敌:难怪小公司那么挑剔,让你们这些大佬把位置拿了
点赞 评论 收藏
分享
05-30 12:03
山西大学 C++
offer来了我跪着...:不是骗子,等到测评那一步就知道为啥这么高工资了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务