fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. long long cnt[1000000+5];
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(0);
  7. int t; cin>>t;
  8. for (int i=1;i<=1000000;i++){
  9. for (int j=i;j<=1000000;j+=i){// i là ước của j , duyệt bội của i thì=> i là ước của j
  10. // có nghĩa là mỗi lần duyệt đến j thì i là ước thì cnt[j]++ là tăng ước lên 1 do i là ước j
  11. cnt[j]+=i;
  12. }
  13. }
  14. while (t--){
  15. int x; cin>>x;
  16. cout<<cnt[x]<<"\n";
  17. }
  18. return 0;
  19. }
Success #stdin #stdout 0.06s 11296KB
stdin
3
6
10
12
stdout
12
18
28