------
## 最终结论
```python
def longestSubstring(s, k):
    if len(s) < k:
        return 0
    
    # Function to find the length of the longest substring
    def helper(subs):
        if len(subs) < k:
            return 0
        
        # Count frequency of each character
        freq = {}
        for char in subs:
            freq[char] = freq.get(char, 0) + 1
        
        # Check for characters that appear less than k times
        for char in freq:
            if freq[char] < k:
                # Split the string and recursively check each part
                return max(helper(part) for part in subs.split(char))
        
        # If all characters meet the requirement, return length of the substring
        return len(subs)
    
    return helper(s)

# Example usage:
print(longestSubstring("aaabb", 3))  # Output: 3
print(longestSubstring("ababbc", 2)) # Output: 5
```