2022-01-05
5777 ワード
📌 約数と加算(プログラマ1級)
ループ約数の個数と加算(プログラマ1級)
百草
ループ約数の個数と加算(プログラマ1級)
百草
class Solution {
public int solution(int left, int right) {
int answer = 0;
int[] count = new int[right+1];
for(int i=1; i<=right; i++)
for(int k=1; k<=right/i; k++)
count[i*k]++;
for(int i=left; i<=right; i++) {
if(count[i]%2 ==0){
answer += i;
continue;
}
answer -= i;
}
return answer;
}
}
見習うclass Solution {
public int solution(int left, int right) {
int answer = 0;
for(int i=left; i<=right; i++)
answer += (i % Math.sqrt(i) == 0 ? -i : i);
return answer;
}
}
Reference
この問題について(2022-01-05), 我々は、より多くの情報をここで見つけました https://velog.io/@kureungkureung/2022-01-05テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol